diff options
106 files changed, 3043 insertions, 3883 deletions
diff --git a/.clang-format b/.clang-format index a17d1800..c3c4f3e1 100644 --- a/.clang-format +++ b/.clang-format @@ -1,3 +1,3 @@ --- Language: Cpp -BasedOnStyle: Microsoft +BasedOnStyle: Google diff --git a/Private/HALKit/AMD64/ACPI/ACPI.hpp b/Private/HALKit/AMD64/ACPI/ACPI.hpp index 590358ff..aa408c6f 100644 --- a/Private/HALKit/AMD64/ACPI/ACPI.hpp +++ b/Private/HALKit/AMD64/ACPI/ACPI.hpp @@ -13,60 +13,53 @@ #include <NewKit/Defines.hpp> namespace hCore { - class SDT { - public: - Char Signature[4]; - UInt32 Length; - UInt8 Revision; - Char Checksum; - Char OemId[6]; - Char OemTableId[8]; - UInt32 OemRev; - UInt32 CreatorID; - UInt32 CreatorRevision; - }; +class SDT { + public: + Char Signature[4]; + UInt32 Length; + UInt8 Revision; + Char Checksum; + Char OemId[6]; + Char OemTableId[8]; + UInt32 OemRev; + UInt32 CreatorID; + UInt32 CreatorRevision; +}; - class RSDP : public SDT - { - public: - UInt32 RsdtAddress; - UIntPtr XsdtAddress; - UInt8 ExtendedChecksum; - UInt8 Reserved0[3]; +class RSDP : public SDT { + public: + UInt32 RsdtAddress; + UIntPtr XsdtAddress; + UInt8 ExtendedChecksum; + UInt8 Reserved0[3]; +}; - }; +class ConfigHeader { + public: + UInt64 BaseAddress; + UInt16 PciSegGroup; + UInt8 StartBus; + UInt8 EndBus; + UInt32 Reserved; +}; - class ConfigHeader - { - public: - UInt64 BaseAddress; - UInt16 PciSegGroup; - UInt8 StartBus; - UInt8 EndBus; - UInt32 Reserved; +enum class AddressSpace : UInt8 { + SystemMemory = 0, + SystemIO = 1, + Pci = 2, + Controller = 3, + SmBus = 4, + Invalid = 0xFF, +}; - }; +class Address { + public: + AddressSpace AddressSpaceId; + UInt8 RegisterBitWidth; + UInt8 RegisterBitOffset; + UInt8 Reserved; + UIntPtr Address; +}; +} // namespace hCore - enum class AddressSpace : UInt8 - { - SystemMemory = 0, - SystemIO = 1, - Pci = 2, - Controller = 3, - SmBus = 4, - Invalid = 0xFF, - }; - - class Address - { - public: - AddressSpace AddressSpaceId; - UInt8 RegisterBitWidth; - UInt8 RegisterBitOffset; - UInt8 Reserved; - UIntPtr Address; - - }; -} // namespace hCore - -#endif // !_INC_ACPI_MANAGER_H +#endif // !_INC_ACPI_MANAGER_H diff --git a/Private/HALKit/AMD64/ACPI/ACPIManager.hpp b/Private/HALKit/AMD64/ACPI/ACPIManager.hpp index 63afe972..385ea854 100644 --- a/Private/HALKit/AMD64/ACPI/ACPIManager.hpp +++ b/Private/HALKit/AMD64/ACPI/ACPIManager.hpp @@ -15,38 +15,36 @@ #include <NewKit/Defines.hpp> #include <NewKit/Ref.hpp> -namespace hCore -{ - class ACPIManager - { - public: - ACPIManager(voidPtr rsdptr); +namespace hCore { +class ACPIManager { + public: + ACPIManager(voidPtr rsdptr); - public: - ~ACPIManager() = default; + public: + ~ACPIManager() = default; - ACPIManager &operator=(const ACPIManager &) = default; + ACPIManager &operator=(const ACPIManager &) = default; - ACPIManager(const ACPIManager &) = default; + ACPIManager(const ACPIManager &) = default; - public: - void Shutdown(); // shutdown - void Reset(); // soft-reboot + public: + void Shutdown(); // shutdown + void Reset(); // soft-reboot - ErrorOr <voidPtr> Find(const char *signature); + ErrorOr<voidPtr> Find(const char *signature); - bool Checksum(const char *checksum, SSizeT len); // watch for collides! + bool Checksum(const char *checksum, SSizeT len); // watch for collides! - public: - ErrorOr <voidPtr> operator[](const char *signature) { - return this->Find(signature); - } + public: + ErrorOr<voidPtr> operator[](const char *signature) { + return this->Find(signature); + } - private: - VoidPtr m_Rsdp; // pointer to root descriptor. - SSizeT m_Entries; // number of entries, -1 tells that no invalid entries were found. + private: + VoidPtr m_Rsdp; // pointer to root descriptor. + SSizeT m_Entries; // number of entries, -1 tells that no invalid entries were + // found. +}; +} // namespace hCore - }; -} // namespace hCore - -#endif // !_INC_ACPI_H +#endif // !_INC_ACPI_H diff --git a/Private/HALKit/AMD64/ACPIManagerAMD64.cpp b/Private/HALKit/AMD64/ACPIManagerAMD64.cpp index 0f5e6f68..0ca172a9 100644 --- a/Private/HALKit/AMD64/ACPIManagerAMD64.cpp +++ b/Private/HALKit/AMD64/ACPIManagerAMD64.cpp @@ -8,85 +8,62 @@ */ #include <HALKit/AMD64/ACPI/ACPIManager.hpp> -#include <NewKit/String.hpp> - #include <HALKit/AMD64/Processor.hpp> +#include <NewKit/String.hpp> -namespace hCore -{ -ACPIManager::ACPIManager(voidPtr rsdPtr) : m_Rsdp(rsdPtr), m_Entries(0) -{ - RSDP *_rsdPtr = reinterpret_cast<RSDP *>(this->m_Rsdp); +namespace hCore { +ACPIManager::ACPIManager(voidPtr rsdPtr) : m_Rsdp(rsdPtr), m_Entries(0) { + RSDP *_rsdPtr = reinterpret_cast<RSDP *>(this->m_Rsdp); - MUST_PASS(_rsdPtr); - MUST_PASS(_rsdPtr->Revision >= 2); + MUST_PASS(_rsdPtr); + MUST_PASS(_rsdPtr->Revision >= 2); } -void ACPIManager::Shutdown() -{ -} -void ACPIManager::Reset() -{ -} +void ACPIManager::Shutdown() {} +void ACPIManager::Reset() {} -ErrorOr<voidPtr> ACPIManager::Find(const char *signature) -{ - MUST_PASS(m_Rsdp); +ErrorOr<voidPtr> ACPIManager::Find(const char *signature) { + MUST_PASS(m_Rsdp); - if (!signature) - return ErrorOr<voidPtr>{-2}; + if (!signature) return ErrorOr<voidPtr>{-2}; - if (*signature == 0) - return ErrorOr<voidPtr>{-3}; + if (*signature == 0) return ErrorOr<voidPtr>{-3}; - RSDP *rsdPtr = reinterpret_cast<RSDP *>(this->m_Rsdp); + RSDP *rsdPtr = reinterpret_cast<RSDP *>(this->m_Rsdp); - auto xsdt = rsdPtr->XsdtAddress; - SizeT num = (rsdPtr->Length + sizeof(SDT)) / 8; + auto xsdt = rsdPtr->XsdtAddress; + SizeT num = (rsdPtr->Length + sizeof(SDT)) / 8; - for (Size index = 0; index < num; ++index) - { - SDT *sdt = reinterpret_cast<SDT *>(xsdt + sizeof(SDT) + index * 8); + for (Size index = 0; index < num; ++index) { + SDT *sdt = reinterpret_cast<SDT *>(xsdt + sizeof(SDT) + index * 8); - if (!Checksum(sdt->Signature, 4)) - panic(RUNTIME_CHECK_ACPI); + if (!Checksum(sdt->Signature, 4)) panic(RUNTIME_CHECK_ACPI); - if (StringBuilder::Equals(const_cast<const char *>(sdt->Signature), signature)) - return ErrorOr<voidPtr>(reinterpret_cast<voidPtr>(sdt)); - } + if (StringBuilder::Equals(const_cast<const char *>(sdt->Signature), + signature)) + return ErrorOr<voidPtr>(reinterpret_cast<voidPtr>(sdt)); + } - return ErrorOr<voidPtr>{-1}; + return ErrorOr<voidPtr>{-1}; } -bool ACPIManager::Checksum(const char *checksum, SSizeT len) -{ - if (len == 0) - return -1; +bool ACPIManager::Checksum(const char *checksum, SSizeT len) { + if (len == 0) return -1; - char chr = 0; + char chr = 0; - for (int index = 0; index < len; ++index) - { - chr += checksum[index]; - } + for (int index = 0; index < len; ++index) { + chr += checksum[index]; + } - return chr == 0; + return chr == 0; } -void rt_shutdown_acpi_qemu_20(void) -{ - HAL::out16(0xb004, 0x2000); -} +void rt_shutdown_acpi_qemu_20(void) { HAL::out16(0xb004, 0x2000); } -void rt_shutdown_acpi_qemu_30_plus(void) -{ - HAL::out16(0x604, 0x2000); -} +void rt_shutdown_acpi_qemu_30_plus(void) { HAL::out16(0x604, 0x2000); } -void rt_shutdown_acpi_virtualbox(void) -{ - HAL::out16(0x4004, 0x3400); -} +void rt_shutdown_acpi_virtualbox(void) { HAL::out16(0x4004, 0x3400); } /// you'll have to parse the MADT otherwise! -} // namespace hCore +} // namespace hCore diff --git a/Private/HALKit/AMD64/CoreInterruptHandlerAMD64.cpp b/Private/HALKit/AMD64/CoreInterruptHandlerAMD64.cpp index fd037c5f..23262109 100644 --- a/Private/HALKit/AMD64/CoreInterruptHandlerAMD64.cpp +++ b/Private/HALKit/AMD64/CoreInterruptHandlerAMD64.cpp @@ -8,75 +8,74 @@ */ #include <ArchKit/Arch.hpp> -#include <NewKit/String.hpp> #include <KernelKit/ProcessManager.hpp> +#include <NewKit/String.hpp> -extern "C" void idt_handle_system_call(hCore::UIntPtr rsp) -{ - hCore::HAL::StackFrame *sf = reinterpret_cast<hCore::HAL::StackFrame*>(rsp); - rt_syscall_handle(sf); +extern "C" void idt_handle_system_call(hCore::UIntPtr rsp) { + hCore::HAL::StackFrame *sf = reinterpret_cast<hCore::HAL::StackFrame *>(rsp); + rt_syscall_handle(sf); - hCore::kcout << "System Call with ID: " << hCore::StringBuilder::FromInt("syscall{%}", sf->SID); + hCore::kcout << "System Call with ID: " + << hCore::StringBuilder::FromInt("syscall{%}", sf->SID); } -extern "C" void idt_handle_gpf(hCore::UIntPtr rsp) -{ - MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent()); +extern "C" void idt_handle_gpf(hCore::UIntPtr rsp) { + MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent()); - hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp); + hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp); - hCore::kcout << "General Protection Fault, Caused by " - << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); + hCore::kcout + << "General Protection Fault, Caused by " + << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); - hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); } -extern "C" void idt_handle_scheduler(hCore::UIntPtr rsp) -{ - hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp); +extern "C" void idt_handle_scheduler(hCore::UIntPtr rsp) { + hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp); - hCore::kcout << "Will be scheduled back later " - << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); + hCore::kcout + << "Will be scheduled back later " + << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); - /// schedule another process. - if (!hCore::ProcessHelper::StartScheduling()) - { - hCore::kcout << "Let's continue schedule this process...\r\n"; - } + /// schedule another process. + if (!hCore::ProcessHelper::StartScheduling()) { + hCore::kcout << "Let's continue schedule this process...\r\n"; + } } -extern "C" void idt_handle_pf(hCore::UIntPtr rsp) -{ - hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp); +extern "C" void idt_handle_pf(hCore::UIntPtr rsp) { + hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp); - MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent()); + MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent()); - hCore::kcout << "Segmentation Fault, Caused by " - << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); + hCore::kcout + << "Segmentation Fault, Caused by " + << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); - hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); } -extern "C" void idt_handle_math(hCore::UIntPtr rsp) -{ - hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp); +extern "C" void idt_handle_math(hCore::UIntPtr rsp) { + hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp); - MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent()); + MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent()); - hCore::kcout << "Math error, Caused by " - << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); + hCore::kcout + << "Math error, Caused by " + << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); - hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); } -extern "C" void idt_handle_generic(hCore::UIntPtr rsp) -{ - hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp); +extern "C" void idt_handle_generic(hCore::UIntPtr rsp) { + hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp); - MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent()); + MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent()); - hCore::kcout << "Processor error, Caused by " - << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); + hCore::kcout + << "Processor error, Caused by " + << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); - hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); } diff --git a/Private/HALKit/AMD64/CoreMultiProcessingAMD64.cpp b/Private/HALKit/AMD64/CoreMultiProcessingAMD64.cpp index 14a7a06b..330a90e6 100644 --- a/Private/HALKit/AMD64/CoreMultiProcessingAMD64.cpp +++ b/Private/HALKit/AMD64/CoreMultiProcessingAMD64.cpp @@ -7,128 +7,121 @@ * ======================================================== */ -#include <HALKit/AMD64/Processor.hpp> #include <HALKit/AMD64/ACPI/ACPIManager.hpp> +#include <HALKit/AMD64/Processor.hpp> /////////////////////////////////////////////////////////////////////////////////////// //! NOTE: fGSI stands 'Field Global System Interrupt' -namespace hCore::HAL -{ - constexpr Int32 kThreadAPIC = 0; - constexpr Int32 kThreadLAPIC = 1; - constexpr Int32 kThreadIOAPIC = 2; - constexpr Int32 kThreadAPIC64 = 3; - constexpr Int32 kThreadBoot = 4; - - /* - * - * this is used to store info about the current running thread - * we use this struct to determine if we can use it, or mark it as used or on sleep. - * - */ - - struct ProcessorInfoAMD64 final - { - Int32 ThreadType; - UIntPtr JumpAddress; - - struct - { - UInt32 Code; - UInt32 Data; - UInt32 BSS; - } Selector; - }; - - static voidPtr kApicMadt = nullptr; - static const char* kApicSignature = "APIC"; - - struct Madt final - { - char fMag[4]; - Int32 fLength; - char fRev; - - struct MadtAddress final - { - UInt32 fPhysicalAddress; - UInt32 fFlags; // 1 = Dual Legacy PICs installed - - Char fType; - Char fRecLen; // record length - }; - }; - - struct MadtProcessorLocalApic final - { - Char fProcessorId; - Char fApicId; - UInt32 fFlags; - }; - - struct MadtIOApic final - { - Char fApicId; - Char fReserved; - UInt32 fAddress; - UInt32 fSystemInterruptBase; - }; - - struct MadtInterruptSource final - { - Char fBusSource; - Char fIrqSource; - UInt32 fGSI; - UInt16 fFlags; - }; - - struct MadtInterruptNmi final - { - Char fNmiSource; - Char fReserved; - UInt16 fFlags; - UInt32 fGSI; - }; - - struct MadtLocalApicAddressOverride final { UInt16 fResvered; UIntPtr fAddress; }; +namespace hCore::HAL { +constexpr Int32 kThreadAPIC = 0; +constexpr Int32 kThreadLAPIC = 1; +constexpr Int32 kThreadIOAPIC = 2; +constexpr Int32 kThreadAPIC64 = 3; +constexpr Int32 kThreadBoot = 4; + +/* + * + * this is used to store info about the current running thread + * we use this struct to determine if we can use it, or mark it as used or on + * sleep. + * + */ + +struct ProcessorInfoAMD64 final { + Int32 ThreadType; + UIntPtr JumpAddress; + + struct { + UInt32 Code; + UInt32 Data; + UInt32 BSS; + } Selector; +}; + +static voidPtr kApicMadt = nullptr; +static const char* kApicSignature = "APIC"; + +struct Madt final { + char fMag[4]; + Int32 fLength; + char fRev; + + struct MadtAddress final { + UInt32 fPhysicalAddress; + UInt32 fFlags; // 1 = Dual Legacy PICs installed + + Char fType; + Char fRecLen; // record length + }; +}; + +struct MadtProcessorLocalApic final { + Char fProcessorId; + Char fApicId; + UInt32 fFlags; +}; + +struct MadtIOApic final { + Char fApicId; + Char fReserved; + UInt32 fAddress; + UInt32 fSystemInterruptBase; +}; + +struct MadtInterruptSource final { + Char fBusSource; + Char fIrqSource; + UInt32 fGSI; + UInt16 fFlags; +}; + +struct MadtInterruptNmi final { + Char fNmiSource; + Char fReserved; + UInt16 fFlags; + UInt32 fGSI; +}; + +struct MadtLocalApicAddressOverride final { + UInt16 fResvered; + UIntPtr fAddress; +}; /////////////////////////////////////////////////////////////////////////////////////// - static Madt kApicMadtList[256]; +static Madt kApicMadtList[256]; - Madt* system_find_core(Madt* madt) - { - madt = madt + sizeof(Madt); +Madt* system_find_core(Madt* madt) { + madt = madt + sizeof(Madt); - if (string_compare(madt->fMag, kApicSignature, string_length(kApicSignature)) == 0) - return madt; + if (string_compare(madt->fMag, kApicSignature, + string_length(kApicSignature)) == 0) + return madt; - return nullptr; - } + return nullptr; +} /////////////////////////////////////////////////////////////////////////////////////// - void system_get_cores(voidPtr rsdPtr) - { - auto acpi = ACPIManager(rsdPtr); - kApicMadt = acpi.Find(kApicSignature).Leak().Leak(); - - MUST_PASS(kApicMadt); // MADT must exist. - - SizeT counter = 0UL; - Madt* offset = system_find_core((Madt*)kApicMadt); - //! now find core addresses. - while (offset != nullptr) - { - // calls rt_copy_memory in NewC++ - kApicMadtList[counter] = *offset; - offset = system_find_core(offset); - - ++counter; - } - } +void system_get_cores(voidPtr rsdPtr) { + auto acpi = ACPIManager(rsdPtr); + kApicMadt = acpi.Find(kApicSignature).Leak().Leak(); + + MUST_PASS(kApicMadt); // MADT must exist. + + SizeT counter = 0UL; + Madt* offset = system_find_core((Madt*)kApicMadt); + //! now find core addresses. + while (offset != nullptr) { + // calls rt_copy_memory in NewC++ + kApicMadtList[counter] = *offset; + offset = system_find_core(offset); + + ++counter; + } } +} // namespace hCore::HAL /////////////////////////////////////////////////////////////////////////////////////// diff --git a/Private/HALKit/AMD64/CoreSyscallHandlerAMD64.cpp b/Private/HALKit/AMD64/CoreSyscallHandlerAMD64.cpp index 3e8544e7..ccd81b9a 100644 --- a/Private/HALKit/AMD64/CoreSyscallHandlerAMD64.cpp +++ b/Private/HALKit/AMD64/CoreSyscallHandlerAMD64.cpp @@ -7,19 +7,17 @@ * ======================================================== */ -#include <KernelKit/PermissionSelector.hxx> -#include <HALKit/AMD64/Processor.hpp> - #include <ArchKit/Arch.hpp> +#include <HALKit/AMD64/Processor.hpp> +#include <KernelKit/PermissionSelector.hxx> -hCore::Array<void (*)(hCore::Int32 id, hCore::HAL::StackFrame *), kMaxSyscalls> kSyscalls; +hCore::Array<void (*)(hCore::Int32 id, hCore::HAL::StackFrame *), kMaxSyscalls> + kSyscalls; // IDT System Call Handler. // NOTE: don't trust the user. -extern "C" void rt_syscall_handle(hCore::HAL::StackFrame *stack) -{ - for (hCore::SizeT index = 0UL; index < kMaxSyscalls; ++index) - { - (kSyscalls[index].Leak().Leak())(stack->SID, stack); - } +extern "C" void rt_syscall_handle(hCore::HAL::StackFrame *stack) { + for (hCore::SizeT index = 0UL; index < kMaxSyscalls; ++index) { + (kSyscalls[index].Leak().Leak())(stack->SID, stack); + } } diff --git a/Private/HALKit/AMD64/DebugManager.asm b/Private/HALKit/AMD64/DebugManager.asm index 0c717039..96c7e2f3 100644 --- a/Private/HALKit/AMD64/DebugManager.asm +++ b/Private/HALKit/AMD64/DebugManager.asm @@ -30,4 +30,4 @@ rt_debug_fence: pop rsi ret -;; //////////////////////////////////////////////////// ;;
\ No newline at end of file +;; //////////////////////////////////////////////////// ;; diff --git a/Private/HALKit/AMD64/DebugOutput.cxx b/Private/HALKit/AMD64/DebugOutput.cxx index 8a8705cf..43ab2538 100644 --- a/Private/HALKit/AMD64/DebugOutput.cxx +++ b/Private/HALKit/AMD64/DebugOutput.cxx @@ -7,62 +7,54 @@ * ======================================================== */ -#include <KernelKit/DebugOutput.hpp> - #include <ArchKit/Arch.hpp> +#include <KernelKit/DebugOutput.hpp> #include <NewKit/Utils.hpp> -namespace hCore -{ - namespace Detail - { - constexpr short PORT = 0x3F8; - - bool serial_init() - { - HAL::out8(PORT + 1, 0x00); // Disable all interrupts - HAL::out8(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) - HAL::out8(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud - HAL::out8(PORT + 1, 0x00); // (hi byte) - HAL::out8(PORT + 3, 0x03); // 8 bits, no parity, one stop bit - HAL::out8(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold - HAL::out8(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set - HAL::out8(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip - HAL::out8(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if - // serial returns same byte) - - // Check if serial is faulty (i.e: not same byte as sent) - if (HAL::in8(PORT) != 0xAE) - { +namespace hCore { +namespace Detail { +constexpr short PORT = 0x3F8; + +bool serial_init() { + HAL::out8(PORT + 1, 0x00); // Disable all interrupts + HAL::out8(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) + HAL::out8(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud + HAL::out8(PORT + 1, 0x00); // (hi byte) + HAL::out8(PORT + 3, 0x03); // 8 bits, no parity, one stop bit + HAL::out8(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold + HAL::out8(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set + HAL::out8(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip + HAL::out8(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if + // serial returns same byte) + + // Check if serial is faulty (i.e: not same byte as sent) + if (HAL::in8(PORT) != 0xAE) { #ifdef __DEBUG__ - panic(RUNTIME_CHECK_HANDSHAKE); + panic(RUNTIME_CHECK_HANDSHAKE); #else - return false; + return false; #endif - } + } - // If serial is not faulty set it in normal operation mode - // (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled) - HAL::out8(Detail::PORT + 4, 0x0F); + // If serial is not faulty set it in normal operation mode + // (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled) + HAL::out8(Detail::PORT + 4, 0x0F); - return true; - } - } + return true; +} +} // namespace Detail - void system_io_print(const char *bytes) - { - if (!bytes) - return; +void system_io_print(const char *bytes) { + if (!bytes) return; - SizeT index = 0; - SizeT len = string_length(bytes, 256); + SizeT index = 0; + SizeT len = string_length(bytes, 256); - while (index < len) - { - HAL::out8(Detail::PORT, bytes[index]); - ++index; - } - } + while (index < len) { + HAL::out8(Detail::PORT, bytes[index]); + ++index; + } +} - TerminalDevice kcout(hCore::system_io_print, nullptr); -} // namespace hCore +TerminalDevice kcout(hCore::system_io_print, nullptr); +} // namespace hCore diff --git a/Private/HALKit/AMD64/DebugPort.cxx b/Private/HALKit/AMD64/DebugPort.cxx index 28e3f5e3..764aab0a 100644 --- a/Private/HALKit/AMD64/DebugPort.cxx +++ b/Private/HALKit/AMD64/DebugPort.cxx @@ -13,7 +13,7 @@ #include <ArchKit/Arch.hpp> #define kDebugMaxPorts 16 - + #define kDebugUnboundPort 0xFFFF #define kDebugMag0 'X' @@ -22,45 +22,38 @@ #define kDebugMag3 'G' #define kDebugSourceFile 0 -#define kDebugLine 33 -#define kDebugTeam 43 -#define kDebugEOP 49 +#define kDebugLine 33 +#define kDebugTeam 43 +#define kDebugEOP 49 // after that we have start of additional data. -namespace hCore -{ - typedef Char rt_debug_type[255]; - - class DebuggerPorts final - { - public: - Int16 fPort[kDebugMaxPorts]; - Int16 fBoundCnt; - - }; - - void rt_debug_listen(DebuggerPorts* theHook) noexcept - { - if (theHook == nullptr) - return; - - for (UInt32 i = 0U; i < kDebugMaxPorts; ++i) - { - HAL::out16(theHook->fPort[i], kDebugMag0); - HAL::rt_wait_for_io(); - - HAL::out16(theHook->fPort[i], kDebugMag1); - HAL::rt_wait_for_io(); - - HAL::out16(theHook->fPort[i], kDebugMag2); - HAL::rt_wait_for_io(); - - HAL::out16(theHook->fPort[i], kDebugMag3); - HAL::rt_wait_for_io(); - - if (HAL::in16(theHook->fPort[i] != kDebugUnboundPort)) - theHook->fBoundCnt++; - } - } +namespace hCore { +typedef Char rt_debug_type[255]; + +class DebuggerPorts final { + public: + Int16 fPort[kDebugMaxPorts]; + Int16 fBoundCnt; +}; + +void rt_debug_listen(DebuggerPorts* theHook) noexcept { + if (theHook == nullptr) return; + + for (UInt32 i = 0U; i < kDebugMaxPorts; ++i) { + HAL::out16(theHook->fPort[i], kDebugMag0); + HAL::rt_wait_for_io(); + + HAL::out16(theHook->fPort[i], kDebugMag1); + HAL::rt_wait_for_io(); + + HAL::out16(theHook->fPort[i], kDebugMag2); + HAL::rt_wait_for_io(); + + HAL::out16(theHook->fPort[i], kDebugMag3); + HAL::rt_wait_for_io(); + + if (HAL::in16(theHook->fPort[i] != kDebugUnboundPort)) theHook->fBoundCnt++; + } } +} // namespace hCore diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp index 07cfbecf..25757942 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.cpp +++ b/Private/HALKit/AMD64/HalPageAlloc.cpp @@ -16,46 +16,41 @@ static hCore::UIntPtr kPagePtr = kPagePtrAddress; static hCore::SizeT kPageCnt = 0UL; -namespace hCore -{ - namespace HAL - { - static auto hal_try_alloc_new_page(SizeT sz, Boolean rw, Boolean user) -> PageTable64* - { - char *ptr = &(reinterpret_cast<char*>(kPagePtr))[kPageCnt + 1]; - - PageTable64 *pte = reinterpret_cast<PageTable64*>(ptr); - pte->Rw = rw; - pte->User = user; - pte->Present = true; - - return pte; - } - - auto hal_alloc_page(SizeT sz, Boolean rw, Boolean user) -> PageTable64* - { - for (SizeT i = 0; i < kPageCnt; ++i) - { - PageTable64 *pte = (reinterpret_cast<PageTable64*>(&kPagePtr) + i); - - if (!pte->Present) { - pte->User = user; - pte->Rw = rw; - pte->Present = true; - - return pte; - } - } - - return hal_try_alloc_new_page(sz, rw, user); - } - - auto hal_create_page(Boolean rw, Boolean user) -> UIntPtr - { - PageTable64 *new_pte = hal_alloc_page(sizeof(PageTable64), rw, user); - MUST_PASS(new_pte); - - return reinterpret_cast<UIntPtr>(new_pte); - } - } // namespace HAL -} // namespace hCore +namespace hCore { +namespace HAL { +static auto hal_try_alloc_new_page(SizeT sz, Boolean rw, Boolean user) + -> PageTable64 * { + char *ptr = &(reinterpret_cast<char *>(kPagePtr))[kPageCnt + 1]; + + PageTable64 *pte = reinterpret_cast<PageTable64 *>(ptr); + pte->Rw = rw; + pte->User = user; + pte->Present = true; + + return pte; +} + +auto hal_alloc_page(SizeT sz, Boolean rw, Boolean user) -> PageTable64 * { + for (SizeT i = 0; i < kPageCnt; ++i) { + PageTable64 *pte = (reinterpret_cast<PageTable64 *>(&kPagePtr) + i); + + if (!pte->Present) { + pte->User = user; + pte->Rw = rw; + pte->Present = true; + + return pte; + } + } + + return hal_try_alloc_new_page(sz, rw, user); +} + +auto hal_create_page(Boolean rw, Boolean user) -> UIntPtr { + PageTable64 *new_pte = hal_alloc_page(sizeof(PageTable64), rw, user); + MUST_PASS(new_pte); + + return reinterpret_cast<UIntPtr>(new_pte); +} +} // namespace HAL +} // namespace hCore diff --git a/Private/HALKit/AMD64/HalPageAlloc.hpp b/Private/HALKit/AMD64/HalPageAlloc.hpp index 06a883bf..dc954153 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.hpp +++ b/Private/HALKit/AMD64/HalPageAlloc.hpp @@ -13,11 +13,11 @@ #ifndef PTE_MAX #define PTE_MAX (512) -#endif //! PTE_MAX +#endif //! PTE_MAX #ifndef PTE_ALIGN #define PTE_ALIGN (4096) -#endif //! PTE_ALIGN +#endif //! PTE_ALIGN #define kPagePtrAddress 0x0900000 @@ -29,24 +29,21 @@ extern "C" hCore::UIntPtr read_cr0(); extern "C" hCore::UIntPtr read_cr2(); extern "C" hCore::UIntPtr read_cr3(); -namespace hCore::HAL -{ - struct PageTable64 - { - bool Present: 1; - bool Rw: 1; - bool User: 1; - bool Wt: 1; - bool Cache: 1; - bool Accessed: 1; - hCore::Int32 Reserved: 6; - hCore::UIntPtr PhysicalAddress: 36; - hCore::Int32 Reserved1: 15; - bool ExecDisable: 1; - - }; - - PageTable64 *hal_alloc_page(SizeT sz, Boolean rw, Boolean user); - - UIntPtr hal_create_page(Boolean rw, Boolean user); -} // namespace hCore::HAL +namespace hCore::HAL { +struct PageTable64 { + bool Present : 1; + bool Rw : 1; + bool User : 1; + bool Wt : 1; + bool Cache : 1; + bool Accessed : 1; + hCore::Int32 Reserved : 6; + hCore::UIntPtr PhysicalAddress : 36; + hCore::Int32 Reserved1 : 15; + bool ExecDisable : 1; +}; + +PageTable64 *hal_alloc_page(SizeT sz, Boolean rw, Boolean user); + +UIntPtr hal_create_page(Boolean rw, Boolean user); +} // namespace hCore::HAL diff --git a/Private/HALKit/AMD64/HalRoutines.s b/Private/HALKit/AMD64/HalRoutines.s index ed15418a..78b9e503 100644 --- a/Private/HALKit/AMD64/HalRoutines.s +++ b/Private/HALKit/AMD64/HalRoutines.s @@ -24,4 +24,3 @@ rt_wait_for_io: rt_get_current_context: mov %rbp, %rax ret - diff --git a/Private/HALKit/AMD64/HardwareAPIC.cpp b/Private/HALKit/AMD64/HardwareAPIC.cpp index f78cfe3b..9a058eae 100644 --- a/Private/HALKit/AMD64/HardwareAPIC.cpp +++ b/Private/HALKit/AMD64/HardwareAPIC.cpp @@ -11,36 +11,32 @@ // bugs = 0 -namespace hCore -{ - // @brief wakes up thread. - // wakes up thread from hang. - void rt_wakeup_thread(HAL::StackFrame* stack) - { - __asm__ volatile ("cli"); - - stack->Rbp = stack->R15; - stack->Rsi = stack->Rbp; - - __asm__ volatile ("sti"); - } - - static void __rt_hang_proc(void) - { - while (1) - ; - } - - // @brief makes thread sleep. - // hooks and hangs thread to prevent code from executing. - void rt_hang_thread(HAL::StackFrame* stack) - { - __asm__ volatile ("cli"); - - stack->R15 = stack->Rbp; - stack->Rbp = (HAL::Reg)&__rt_hang_proc; - stack->Rsp = stack->Rbp; - - __asm__ volatile ("sti"); - } -}
\ No newline at end of file +namespace hCore { +// @brief wakes up thread. +// wakes up thread from hang. +void rt_wakeup_thread(HAL::StackFrame* stack) { + __asm__ volatile("cli"); + + stack->Rbp = stack->R15; + stack->Rsi = stack->Rbp; + + __asm__ volatile("sti"); +} + +static void __rt_hang_proc(void) { + while (1) + ; +} + +// @brief makes thread sleep. +// hooks and hangs thread to prevent code from executing. +void rt_hang_thread(HAL::StackFrame* stack) { + __asm__ volatile("cli"); + + stack->R15 = stack->Rbp; + stack->Rbp = (HAL::Reg)&__rt_hang_proc; + stack->Rsp = stack->Rbp; + + __asm__ volatile("sti"); +} +} // namespace hCore diff --git a/Private/HALKit/AMD64/HardwareInit.cpp b/Private/HALKit/AMD64/HardwareInit.cpp index 367f083b..7d769bfa 100644 --- a/Private/HALKit/AMD64/HardwareInit.cpp +++ b/Private/HALKit/AMD64/HardwareInit.cpp @@ -11,12 +11,10 @@ // bugs = 0 -namespace hCore -{ - bool init_hal() - { - // TODO: Hardware Specific stuff. +namespace hCore { +bool init_hal() { + // TODO: Hardware Specific stuff. - return true; - } -}
\ No newline at end of file + return true; +} +} // namespace hCore diff --git a/Private/HALKit/AMD64/Hypervisor.hpp b/Private/HALKit/AMD64/Hypervisor.hpp index 5c321f23..c830ef00 100644 --- a/Private/HALKit/AMD64/Hypervisor.hpp +++ b/Private/HALKit/AMD64/Hypervisor.hpp @@ -12,27 +12,17 @@ #include <NewKit/Defines.hpp> namespace hCore { - MAKE_STRING_ENUM(HYPERVISOR) - ENUM_STRING(Qemu, - "TCGTCGTCGTCG"); - ENUM_STRING(KVM, - " KVMKVMKVM "); - ENUM_STRING(VMWare, - "VMwareVMware"); - ENUM_STRING(VirtualBox, - "VBoxVBoxVBox"); - ENUM_STRING(Xen, - "XenVMMXenVMM"); - ENUM_STRING(Microsoft, - "Microsoft Hv"); - ENUM_STRING(Parallels, - " prl hyperv "); - ENUM_STRING(ParallelsAlt, - " lrpepyh vr "); - ENUM_STRING(Bhyve, - "bhyve bhyve "); - ENUM_STRING(Qnx, - " QNXQVMBSQG "); +MAKE_STRING_ENUM(HYPERVISOR) +ENUM_STRING(Qemu, "TCGTCGTCGTCG"); +ENUM_STRING(KVM, " KVMKVMKVM "); +ENUM_STRING(VMWare, "VMwareVMware"); +ENUM_STRING(VirtualBox, "VBoxVBoxVBox"); +ENUM_STRING(Xen, "XenVMMXenVMM"); +ENUM_STRING(Microsoft, "Microsoft Hv"); +ENUM_STRING(Parallels, " prl hyperv "); +ENUM_STRING(ParallelsAlt, " lrpepyh vr "); +ENUM_STRING(Bhyve, "bhyve bhyve "); +ENUM_STRING(Qnx, " QNXQVMBSQG "); - END_STRING_ENUM() -} // namespace hCore +END_STRING_ENUM() +} // namespace hCore diff --git a/Private/HALKit/AMD64/TIBInstall.asm b/Private/HALKit/AMD64/InstallTIB.asm index 69aa7503..6957e1a6 100644 --- a/Private/HALKit/AMD64/TIBInstall.asm +++ b/Private/HALKit/AMD64/InstallTIB.asm @@ -15,4 +15,4 @@ rt_install_tib: mov rsi, gs ret -;; //////////////////////////////////////////////////// ;;
\ No newline at end of file +;; //////////////////////////////////////////////////// ;; diff --git a/Private/HALKit/AMD64/PCI/Database.cpp b/Private/HALKit/AMD64/PCI/Database.cpp index b3a1961c..daf4bc61 100644 --- a/Private/HALKit/AMD64/PCI/Database.cpp +++ b/Private/HALKit/AMD64/PCI/Database.cpp @@ -9,6 +9,4 @@ #include <KernelKit/PCI/Database.hpp> -namespace hCore -{ -} +namespace hCore {} diff --git a/Private/HALKit/AMD64/PCI/Device.cpp b/Private/HALKit/AMD64/PCI/Device.cpp index f8b5f629..597e936b 100644 --- a/Private/HALKit/AMD64/PCI/Device.cpp +++ b/Private/HALKit/AMD64/PCI/Device.cpp @@ -10,118 +10,103 @@ #include <ArchKit/Arch.hpp> #include <KernelKit/PCI/Device.hpp> +hCore::UInt LumiaPCIReadRaw(hCore::UInt bar, hCore::UShort bus, + hCore::UShort dev, hCore::UShort fun) { + hCore::UInt target = 0x80000000 | ((hCore::UInt)bus << 16) | + ((hCore::UInt)dev << 11) | ((hCore::UInt)fun << 8) | + (bar & 0xFC); -hCore::UInt LumiaPCIReadRaw(hCore::UInt bar, hCore::UShort bus, hCore::UShort dev, hCore::UShort fun) -{ - hCore::UInt target = 0x80000000 | ((hCore::UInt) bus << 16) | ((hCore::UInt) dev << 11) | ((hCore::UInt) fun << 8) | - (bar & 0xFC); + hCore::HAL::out32((hCore::UShort)hCore::PCI::PciConfigKind::ConfigAddress, + target); - hCore::HAL::out32((hCore::UShort) hCore::PCI::PciConfigKind::ConfigAddress, target); + return hCore::HAL::in32((hCore::UShort)hCore::PCI::PciConfigKind::ConfigData); +} + +void LumiaPCISetCfgTarget(hCore::UInt bar, hCore::UShort bus, hCore::UShort dev, + hCore::UShort fun) { + hCore::UInt target = 0x80000000 | ((hCore::UInt)bus << 16) | + ((hCore::UInt)dev << 11) | ((hCore::UInt)fun << 8) | + (bar & ~3); + + hCore::HAL::out32((hCore::UShort)hCore::PCI::PciConfigKind::ConfigAddress, + target); +} + +namespace hCore::PCI { +Device::Device(UShort bus, UShort device, UShort func, UShort bar) + : m_Bus(bus), m_Device(device), m_Function(func), m_Bar(bar) {} + +Device::~Device() {} + +UInt Device::Read(UInt bar, Size sz) { + LumiaPCISetCfgTarget(bar, m_Bus, m_Device, m_Function); + + if (sz == 4) + return HAL::in32((UShort)PciConfigKind::ConfigData + (m_Bar & 3)); + if (sz == 2) + return HAL::in16((UShort)PciConfigKind::ConfigData + (m_Bar & 3)); + if (sz == 1) return HAL::in8((UShort)PciConfigKind::ConfigData + (m_Bar & 3)); + + return 0xFFFF; +} + +void Device::Write(UInt bar, UIntPtr data, Size sz) { + LumiaPCISetCfgTarget(bar, m_Bus, m_Device, m_Function); + + if (sz == 4) + HAL::out32((UShort)PciConfigKind::ConfigData + (m_Bar & 3), (UInt)data); + if (sz == 2) + HAL::out16((UShort)PciConfigKind::ConfigData + (m_Bar & 3), (UShort)data); + if (sz == 1) + HAL::out8((UShort)PciConfigKind::ConfigData + (m_Bar & 3), (UChar)data); +} + +UShort Device::DeviceId() { + return (UShort)(LumiaPCIReadRaw(0x0 >> 16, m_Bus, m_Device, m_Function)); +} - return hCore::HAL::in32((hCore::UShort) hCore::PCI::PciConfigKind::ConfigData); +UShort Device::VendorId() { + return (UShort)(LumiaPCIReadRaw(0x0, m_Bus, m_Device, m_Function) >> 16); } -void LumiaPCISetCfgTarget(hCore::UInt bar, hCore::UShort bus, hCore::UShort dev, hCore::UShort fun) -{ - hCore::UInt target = - 0x80000000 | ((hCore::UInt) bus << 16) | ((hCore::UInt) dev << 11) | ((hCore::UInt) fun << 8) | (bar & ~3); +UShort Device::InterfaceId() { + return (UShort)(LumiaPCIReadRaw(0x0, m_Bus, m_Device, m_Function) >> 16); +} + +UChar Device::Class() { + return (UChar)(LumiaPCIReadRaw(0x08, m_Bus, m_Device, m_Function) >> 24); +} + +UChar Device::Subclass() { + return (UChar)(LumiaPCIReadRaw(0x08, m_Bus, m_Device, m_Function) >> 16); +} + +UChar Device::ProgIf() { + return (UChar)(LumiaPCIReadRaw(0x08, m_Bus, m_Device, m_Function) >> 8); +} + +UChar Device::HeaderType() { + return (UChar)(LumiaPCIReadRaw(0xC, m_Bus, m_Device, m_Function) >> 16); +} + +void Device::EnableMmio() { + bool enable = Read(0x04, sizeof(UChar)) | (1 << 1); + Write(0x04, enable, sizeof(UShort)); +} + +void Device::BecomeBusMaster() { + bool enable = Read(0x04, sizeof(UShort)) | (1 << 2); + Write(0x04, enable, sizeof(UShort)); +} + +UShort Device::Vendor() { + UShort vendor = VendorId(); + + if (vendor != (UShort)PciConfigKind::Invalid) + m_Device = (UShort)Read(0x0, sizeof(UShort)); - hCore::HAL::out32((hCore::UShort) hCore::PCI::PciConfigKind::ConfigAddress, target); + return m_Device; } -namespace hCore::PCI -{ - Device::Device(UShort bus, UShort device, UShort func, UShort bar) - : m_Bus(bus), m_Device(device), m_Function(func), m_Bar(bar) - {} - - Device::~Device() {} - - UInt Device::Read(UInt bar, Size sz) - { - LumiaPCISetCfgTarget(bar, m_Bus, m_Device, m_Function); - - if (sz == 4) - return HAL::in32((UShort) PciConfigKind::ConfigData + (m_Bar & 3)); - if (sz == 2) - return HAL::in16((UShort) PciConfigKind::ConfigData + (m_Bar & 3)); - if (sz == 1) - return HAL::in8((UShort) PciConfigKind::ConfigData + (m_Bar & 3)); - - return 0xFFFF; - } - - void Device::Write(UInt bar, UIntPtr data, Size sz) - { - LumiaPCISetCfgTarget(bar, m_Bus, m_Device, m_Function); - - if (sz == 4) - HAL::out32((UShort) PciConfigKind::ConfigData + (m_Bar & 3), (UInt) data); - if (sz == 2) - HAL::out16((UShort) PciConfigKind::ConfigData + (m_Bar & 3), (UShort) data); - if (sz == 1) - HAL::out8((UShort) PciConfigKind::ConfigData + (m_Bar & 3), (UChar) data); - } - - UShort Device::DeviceId() - { - return (UShort)(LumiaPCIReadRaw(0x0 >> 16, m_Bus, m_Device, m_Function)); - } - - UShort Device::VendorId() - { - return (UShort) (LumiaPCIReadRaw(0x0, m_Bus, m_Device, m_Function) >> 16); - } - - UShort Device::InterfaceId() - { - return (UShort)(LumiaPCIReadRaw(0x0, m_Bus, m_Device, m_Function) >> 16); - } - - UChar Device::Class() - { - return (UChar)(LumiaPCIReadRaw(0x08, m_Bus, m_Device, m_Function) >> 24); - } - - UChar Device::Subclass() - { - return (UChar)(LumiaPCIReadRaw(0x08, m_Bus, m_Device, m_Function) >> 16); - } - - UChar Device::ProgIf() - { - return (UChar)(LumiaPCIReadRaw(0x08, m_Bus, m_Device, m_Function) >> 8); - } - - UChar Device::HeaderType() - { - return (UChar)(LumiaPCIReadRaw(0xC, m_Bus, m_Device, m_Function) >> 16); - } - - void Device::EnableMmio() - { - bool enable = Read(0x04, sizeof(UChar)) | (1 << 1); - Write(0x04, enable, sizeof(UShort)); - } - - void Device::BecomeBusMaster() - { - bool enable = Read(0x04, sizeof(UShort)) | (1 << 2); - Write(0x04, enable, sizeof(UShort)); - } - - UShort Device::Vendor() - { - UShort vendor = VendorId(); - - if (vendor != (UShort) PciConfigKind::Invalid) - m_Device = (UShort) Read(0x0, sizeof(UShort)); - - return m_Device; - } - - Device::operator bool() - { - return VendorId() != (UShort) PciConfigKind::Invalid; - } -} // namespace hCore::PCI +Device::operator bool() { return VendorId() != (UShort)PciConfigKind::Invalid; } +} // namespace hCore::PCI diff --git a/Private/HALKit/AMD64/PCI/Dma.cpp b/Private/HALKit/AMD64/PCI/Dma.cpp index 0b75776b..e52ef743 100644 --- a/Private/HALKit/AMD64/PCI/Dma.cpp +++ b/Private/HALKit/AMD64/PCI/Dma.cpp @@ -10,66 +10,57 @@ #include <KernelKit/PCI/Dma.hpp> namespace hCore { - DMAWrapper::operator bool() { - return m_Address; - } +DMAWrapper::operator bool() { return m_Address; } - bool DMAWrapper::operator!() { - return !m_Address; - } +bool DMAWrapper::operator!() { return !m_Address; } - Boolean DMAWrapper::Check(UIntPtr offset) const { - if (!m_Address) - return false; - if (offset == 0) - return true; +Boolean DMAWrapper::Check(UIntPtr offset) const { + if (!m_Address) return false; + if (offset == 0) return true; - kcout << "[DMAWrapper::IsIn] Checking offset..\n"; - return reinterpret_cast<UIntPtr>(m_Address) >= offset; - } + kcout << "[DMAWrapper::IsIn] Checking offset..\n"; + return reinterpret_cast<UIntPtr>(m_Address) >= offset; +} - bool DMAWrapper::Write(const UIntPtr &bit, const UIntPtr &offset) { - if (!m_Address) - return false; +bool DMAWrapper::Write(const UIntPtr &bit, const UIntPtr &offset) { + if (!m_Address) return false; - kcout << "[DMAWrapper::Write] Writing at address..\n"; + kcout << "[DMAWrapper::Write] Writing at address..\n"; - auto addr = (volatile UIntPtr *) (reinterpret_cast<UIntPtr>(m_Address) + offset); - *addr = bit; + auto addr = + (volatile UIntPtr *)(reinterpret_cast<UIntPtr>(m_Address) + offset); + *addr = bit; - return true; - } + return true; +} - UIntPtr DMAWrapper::Read(const UIntPtr &offset) { - kcout << "[DMAWrapper::Read] checking m_Address..\n"; - if (!m_Address) - return 0; +UIntPtr DMAWrapper::Read(const UIntPtr &offset) { + kcout << "[DMAWrapper::Read] checking m_Address..\n"; + if (!m_Address) return 0; - kcout << "[DMAWrapper::Read] Reading m_Address..\n"; - return *(volatile UIntPtr *) (reinterpret_cast<UIntPtr>(m_Address) + offset);; - } + kcout << "[DMAWrapper::Read] Reading m_Address..\n"; + return *(volatile UIntPtr *)(reinterpret_cast<UIntPtr>(m_Address) + offset); + ; +} - UIntPtr DMAWrapper::operator[](const UIntPtr &offset) { - return this->Read(offset); - } +UIntPtr DMAWrapper::operator[](const UIntPtr &offset) { + return this->Read(offset); +} - OwnPtr <IOBuf<Char *>> DMAFactory::Construct(OwnPtr <DMAWrapper> &dma) { - if (!dma) - return {}; +OwnPtr<IOBuf<Char *>> DMAFactory::Construct(OwnPtr<DMAWrapper> &dma) { + if (!dma) return {}; - OwnPtr < IOBuf < Char * >> dmaOwnPtr = make_ptr < IOBuf < Char * >, char * > - (reinterpret_cast<char*>(dma->m_Address)); + OwnPtr<IOBuf<Char *>> dmaOwnPtr = + make_ptr<IOBuf<Char *>, char *>(reinterpret_cast<char *>(dma->m_Address)); - if (!dmaOwnPtr) - return {}; + if (!dmaOwnPtr) return {}; - kcout << "Returning the new OwnPtr<IOBuf<Char*>>!\r\n"; - return dmaOwnPtr; - } + kcout << "Returning the new OwnPtr<IOBuf<Char*>>!\r\n"; + return dmaOwnPtr; +} - DMAWrapper& DMAWrapper::operator=(voidPtr Ptr) - { - m_Address = Ptr; - return *this; - } -} // namespace hCore +DMAWrapper &DMAWrapper::operator=(voidPtr Ptr) { + m_Address = Ptr; + return *this; +} +} // namespace hCore diff --git a/Private/HALKit/AMD64/PCI/Express.cpp b/Private/HALKit/AMD64/PCI/Express.cpp index dca3f37b..eaf886b7 100644 --- a/Private/HALKit/AMD64/PCI/Express.cpp +++ b/Private/HALKit/AMD64/PCI/Express.cpp @@ -9,5 +9,4 @@ #include <KernelKit/PCI/Express.hpp> -namespace hCore { -}
\ No newline at end of file +namespace hCore {} diff --git a/Private/HALKit/AMD64/PCI/Iterator.cpp b/Private/HALKit/AMD64/PCI/Iterator.cpp index 6f80d496..3d357901 100644 --- a/Private/HALKit/AMD64/PCI/Iterator.cpp +++ b/Private/HALKit/AMD64/PCI/Iterator.cpp @@ -9,31 +9,29 @@ #include <KernelKit/PCI/Iterator.hpp> -#define PCI_ITERATOR_FIND_AND_UNWRAP(DEV, SZ) \ - if (DEV.Leak()) \ - return DEV.Leak(); +#define PCI_ITERATOR_FIND_AND_UNWRAP(DEV, SZ) \ + if (DEV.Leak()) return DEV.Leak(); namespace hCore::PCI { - Iterator::Iterator(const Types::PciDeviceKind &type) { - // probe devices. - for (int bus = 0; bus < ME_BUS_COUNT; ++bus) { - for (int device = 0; device < ME_DEVICE_COUNT; ++device) { - for (int function = 0; function < ME_FUNCTION_COUNT; ++function) { - Device dev(bus, device, function, 0); +Iterator::Iterator(const Types::PciDeviceKind &type) { + // probe devices. + for (int bus = 0; bus < ME_BUS_COUNT; ++bus) { + for (int device = 0; device < ME_DEVICE_COUNT; ++device) { + for (int function = 0; function < ME_FUNCTION_COUNT; ++function) { + Device dev(bus, device, function, 0); - if (dev.Class() == (UChar) type) { - m_Devices[bus].Leak().Leak() = dev; - } - } - } + if (dev.Class() == (UChar)type) { + m_Devices[bus].Leak().Leak() = dev; } + } } + } +} - Iterator::~Iterator() { - } +Iterator::~Iterator() {} - Ref<PCI::Device> Iterator::operator[](const Size &sz) { - PCI_ITERATOR_FIND_AND_UNWRAP(m_Devices[sz], sz); - return {}; - } -} // namespace hCore::PCI +Ref<PCI::Device> Iterator::operator[](const Size &sz) { + PCI_ITERATOR_FIND_AND_UNWRAP(m_Devices[sz], sz); + return {}; +} +} // namespace hCore::PCI diff --git a/Private/HALKit/AMD64/PCI/PCI.cpp b/Private/HALKit/AMD64/PCI/PCI.cpp index 66770939..833bce22 100644 --- a/Private/HALKit/AMD64/PCI/PCI.cpp +++ b/Private/HALKit/AMD64/PCI/PCI.cpp @@ -7,4 +7,4 @@ * ======================================================== */ -#include <KernelKit/PCI/PCI.hpp>
\ No newline at end of file +#include <KernelKit/PCI/PCI.hpp> diff --git a/Private/HALKit/AMD64/PlatformAMD64.cpp b/Private/HALKit/AMD64/PlatformAMD64.cpp index 0bade8dc..3005cc07 100644 --- a/Private/HALKit/AMD64/PlatformAMD64.cpp +++ b/Private/HALKit/AMD64/PlatformAMD64.cpp @@ -9,50 +9,39 @@ #include <ArchKit/Arch.hpp> -namespace hCore::HAL -{ -namespace Detail -{ -struct RegisterAMD64 final -{ - UIntPtr base; - UShort limit; +namespace hCore::HAL { +namespace Detail { +struct RegisterAMD64 final { + UIntPtr base; + UShort limit; }; -} // namespace Detail +} // namespace Detail -void GDTLoader::Load(Register64 &gdt) -{ - Detail::RegisterAMD64 *reg = new Detail::RegisterAMD64(); - MUST_PASS(reg); +void GDTLoader::Load(Register64 &gdt) { + Detail::RegisterAMD64 *reg = new Detail::RegisterAMD64(); + MUST_PASS(reg); - reg->base = gdt.Base; - reg->limit = gdt.Limit; + reg->base = gdt.Base; + reg->limit = gdt.Limit; - rt_cli(); - load_gdt(reg); - rt_sti(); + rt_cli(); + load_gdt(reg); + rt_sti(); } -void IDTLoader::Load(Register64 &idt) -{ - Detail::RegisterAMD64 *reg = new Detail::RegisterAMD64(); - MUST_PASS(reg); +void IDTLoader::Load(Register64 &idt) { + Detail::RegisterAMD64 *reg = new Detail::RegisterAMD64(); + MUST_PASS(reg); - reg->base = idt.Base; - reg->limit = idt.Limit; + reg->base = idt.Base; + reg->limit = idt.Limit; - rt_cli(); - load_idt(reg); - rt_sti(); + rt_cli(); + load_idt(reg); + rt_sti(); } -void GDTLoader::Load(Ref<Register64> &gdt) -{ - GDTLoader::Load(gdt.Leak()); -} +void GDTLoader::Load(Ref<Register64> &gdt) { GDTLoader::Load(gdt.Leak()); } -void IDTLoader::Load(Ref<Register64> &idt) -{ - IDTLoader::Load(idt.Leak()); -} -} // namespace hCore::HAL +void IDTLoader::Load(Ref<Register64> &idt) { IDTLoader::Load(idt.Leak()); } +} // namespace hCore::HAL diff --git a/Private/HALKit/AMD64/ProcessPrimitives.cxx b/Private/HALKit/AMD64/ProcessPrimitives.cxx index f5b19861..557eb7f0 100644 --- a/Private/HALKit/AMD64/ProcessPrimitives.cxx +++ b/Private/HALKit/AMD64/ProcessPrimitives.cxx @@ -7,20 +7,19 @@ * ======================================================== */ -#include "NewKit/Defines.hpp" #include <KernelKit/ProcessManager.hpp> +#include "NewKit/Defines.hpp" + using namespace hCore; -Void Process::AssignStart(UIntPtr &imageStart) noexcept -{ - if (imageStart == 0) - this->Crash(); +Void Process::AssignStart(UIntPtr &imageStart) noexcept { + if (imageStart == 0) this->Crash(); #ifdef __x86_64__ - this->StackFrame->Rbp = imageStart; + this->StackFrame->Rbp = imageStart; #elif defined(__powerpc) - // link return register towards the __start symbol. - this->StackFrame->R3 = imageStart; + // link return register towards the __start symbol. + this->StackFrame->R3 = imageStart; #endif } diff --git a/Private/HALKit/AMD64/Processor.cpp b/Private/HALKit/AMD64/Processor.cpp index 4e1216e6..893f4a58 100644 --- a/Private/HALKit/AMD64/Processor.cpp +++ b/Private/HALKit/AMD64/Processor.cpp @@ -14,64 +14,45 @@ * @brief This file is about processor specific functions (in/out...) */ -namespace hCore::HAL -{ -void out8(UInt16 port, UInt8 value) -{ - asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); +namespace hCore::HAL { +void out8(UInt16 port, UInt8 value) { + asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); } -void out16(UInt16 port, UInt16 value) -{ - asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); +void out16(UInt16 port, UInt16 value) { + asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); } -void out32(UInt16 port, UInt32 value) -{ - asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); +void out32(UInt16 port, UInt32 value) { + asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); } -UInt8 in8(UInt16 port) -{ - UInt8 value = 0UL; - asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); +UInt8 in8(UInt16 port) { + UInt8 value = 0UL; + asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); - return value; + return value; } -UInt16 in16(UInt16 port) -{ - UInt16 value = 0UL; - asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); +UInt16 in16(UInt16 port) { + UInt16 value = 0UL; + asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); - return value; + return value; } -UInt32 in32(UInt16 port) -{ - UInt32 value = 0UL; - asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); +UInt32 in32(UInt16 port) { + UInt32 value = 0UL; + asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); - return value; + return value; } -void rt_halt() -{ - asm volatile("hlt"); -} +void rt_halt() { asm volatile("hlt"); } -void rt_cli() -{ - asm volatile("cli"); -} +void rt_cli() { asm volatile("cli"); } -void rt_sti() -{ - asm volatile("sti"); -} +void rt_sti() { asm volatile("sti"); } -void rt_cld() -{ - asm volatile("cld"); -} -} // namespace hCore::HAL +void rt_cld() { asm volatile("cld"); } +} // namespace hCore::HAL diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp index ca5db0ed..82eed130 100644 --- a/Private/HALKit/AMD64/Processor.hpp +++ b/Private/HALKit/AMD64/Processor.hpp @@ -9,122 +9,110 @@ #pragma once -#include <NewKit/Defines.hpp> #include <NewKit/Array.hpp> +#include <NewKit/Defines.hpp> #include <NewKit/Utils.hpp> #define IsActiveLow(flag) (flag & 2) #define IsLevelTriggered(flag) (flag & 8) -namespace hCore::HAL -{ - extern "C" UChar in8(UInt16 port); - extern "C" UShort in16(UInt16 port); - extern "C" UInt in32(UInt16 port); - - extern "C" void out16(UShort port, UShort byte); - extern "C" void out8(UShort port, UChar byte); - extern "C" void out32(UShort port, UInt byte); - - extern "C" void rt_wait_for_io(); - extern "C" void rt_halt(); - extern "C" void rt_cli(); - extern "C" void rt_sti(); - extern "C" void rt_cld(); - - class Register64 - { - public: - UIntPtr Base; - UShort Limit; - - operator bool() { return Base > Limit; } - - }; - - using RawRegister = UInt64; - - using InterruptId = UShort; /* For each element in the IVT */ - using interruptTrap = UIntPtr(UIntPtr sp); - - typedef UIntPtr Reg; - - struct __attribute__((packed)) StackFrame - { - Reg Rax; - Reg Rbx; - Reg Rcx; - Reg Rdx; - Reg Rsi; - Reg Rdi; - Reg Rbp; - Reg Rsp; - Reg R8; - Reg R9; - Reg R10; - Reg R11; - Reg R12; - Reg R13; - Reg R14; - Reg R15; // Reserved: Multi Processor manager (Hal) - Reg SID; // Reserved: system call id (Hal) - }; - - typedef StackFrame* StackFramePtr; - - class InterruptDescriptor final - { - public: - UShort Offset; - UShort Selector; - UChar Ist; - UChar Atrributes; - - UShort SecondOffset; - UInt ThirdOffset; - UInt Zero; - - operator bool() { return Offset != 0xFFFF; } - - }; - - using InterruptDescriptorArray = Array<InterruptDescriptor, 256>; - - class SegmentDescriptor final - { - public: - UIntPtr Base; - UIntPtr BaseMiddle; - UIntPtr BaseHigh; - - UShort Limit; - UChar Gran; - UChar AB; - - operator bool() { return Base > Limit; } - - }; - - using SegmentArray = Array<SegmentDescriptor, 6>; - - class GDTLoader final - { - public: - static void Load(Register64 &gdt); - static void Load(Ref<Register64> &gdt); - - }; - - class IDTLoader final - { - public: - static void Load(Register64 &idt); - static void Load(Ref<Register64> &idt); - - }; - - void system_get_cores(voidPtr rsdPtr); -} // namespace hCore::HAL +namespace hCore::HAL { +extern "C" UChar in8(UInt16 port); +extern "C" UShort in16(UInt16 port); +extern "C" UInt in32(UInt16 port); + +extern "C" void out16(UShort port, UShort byte); +extern "C" void out8(UShort port, UChar byte); +extern "C" void out32(UShort port, UInt byte); + +extern "C" void rt_wait_for_io(); +extern "C" void rt_halt(); +extern "C" void rt_cli(); +extern "C" void rt_sti(); +extern "C" void rt_cld(); + +class Register64 { + public: + UIntPtr Base; + UShort Limit; + + operator bool() { return Base > Limit; } +}; + +using RawRegister = UInt64; + +using InterruptId = UShort; /* For each element in the IVT */ +using interruptTrap = UIntPtr(UIntPtr sp); + +typedef UIntPtr Reg; + +struct __attribute__((packed)) StackFrame { + Reg Rax; + Reg Rbx; + Reg Rcx; + Reg Rdx; + Reg Rsi; + Reg Rdi; + Reg Rbp; + Reg Rsp; + Reg R8; + Reg R9; + Reg R10; + Reg R11; + Reg R12; + Reg R13; + Reg R14; + Reg R15; // Reserved: Multi Processor manager (Hal) + Reg SID; // Reserved: system call id (Hal) +}; + +typedef StackFrame *StackFramePtr; + +class InterruptDescriptor final { + public: + UShort Offset; + UShort Selector; + UChar Ist; + UChar Atrributes; + + UShort SecondOffset; + UInt ThirdOffset; + UInt Zero; + + operator bool() { return Offset != 0xFFFF; } +}; + +using InterruptDescriptorArray = Array<InterruptDescriptor, 256>; + +class SegmentDescriptor final { + public: + UIntPtr Base; + UIntPtr BaseMiddle; + UIntPtr BaseHigh; + + UShort Limit; + UChar Gran; + UChar AB; + + operator bool() { return Base > Limit; } +}; + +using SegmentArray = Array<SegmentDescriptor, 6>; + +class GDTLoader final { + public: + static void Load(Register64 &gdt); + static void Load(Ref<Register64> &gdt); +}; + +class IDTLoader final { + public: + static void Load(Register64 &idt); + static void Load(Ref<Register64> &idt); +}; + +void system_get_cores(voidPtr rsdPtr); +} // namespace hCore::HAL extern "C" void idt_handle_system_call(hCore::UIntPtr rsp); extern "C" void idt_handle_generic(hCore::UIntPtr rsp); diff --git a/Private/HALKit/AMD64/SMPCoreManager.asm b/Private/HALKit/AMD64/SMPCoreManager.asm index ed56d7db..40664a7e 100644 --- a/Private/HALKit/AMD64/SMPCoreManager.asm +++ b/Private/HALKit/AMD64/SMPCoreManager.asm @@ -22,4 +22,4 @@ rt_do_context_switch_unprotected: mov [rdi+0], rax mov [rdi+8], rbx mov [rdi+16], rcx - ret
\ No newline at end of file + ret diff --git a/Private/HALKit/AMD64/crti.s b/Private/HALKit/AMD64/crti.s index 5856b9e9..a85782ea 100644 --- a/Private/HALKit/AMD64/crti.s +++ b/Private/HALKit/AMD64/crti.s @@ -14,5 +14,3 @@ _fini: push %rbp movq %rsp, %rbp /* gcc will nicely put the contents of crtbegin.o's .fini section here. */ - - diff --git a/Private/HALKit/AMD64/crtn.s b/Private/HALKit/AMD64/crtn.s index acc8faa5..b446d9f3 100644 --- a/Private/HALKit/AMD64/crtn.s +++ b/Private/HALKit/AMD64/crtn.s @@ -8,4 +8,3 @@ /* gcc will nicely put the contents of crtend.o's .fini section here. */ popq %rbp ret - diff --git a/Private/HALKit/PowerPC/CoreSyscallHandlerPowerPC.cpp b/Private/HALKit/PowerPC/CoreSyscallHandlerPowerPC.cpp index 6a723cba..ee300501 100644 --- a/Private/HALKit/PowerPC/CoreSyscallHandlerPowerPC.cpp +++ b/Private/HALKit/PowerPC/CoreSyscallHandlerPowerPC.cpp @@ -10,12 +10,11 @@ #include <ArchKit/Arch.hpp> #include <NewKit/Array.hpp> -hCore::Array<void (*)(hCore::Int32 id, hCore::HAL::StackFrame *), kMaxSyscalls> kSyscalls; +hCore::Array<void (*)(hCore::Int32 id, hCore::HAL::StackFrame *), kMaxSyscalls> + kSyscalls; -extern "C" void rt_syscall_handle(hCore::HAL::StackFrame *stack) -{ - for (hCore::SizeT index = 0UL; index < kMaxSyscalls; ++index) - { - (kSyscalls[index].Leak().Leak())(stack->ID, stack); - } +extern "C" void rt_syscall_handle(hCore::HAL::StackFrame *stack) { + for (hCore::SizeT index = 0UL; index < kMaxSyscalls; ++index) { + (kSyscalls[index].Leak().Leak())(stack->ID, stack); + } } diff --git a/Private/HALKit/PowerPC/PCI/Device.cxx b/Private/HALKit/PowerPC/PCI/Device.cxx index e69de29b..8b137891 100644 --- a/Private/HALKit/PowerPC/PCI/Device.cxx +++ b/Private/HALKit/PowerPC/PCI/Device.cxx @@ -0,0 +1 @@ + diff --git a/Private/HALKit/PowerPC/Processor.cpp b/Private/HALKit/PowerPC/Processor.cpp index dc614fa9..e3b207c6 100644 --- a/Private/HALKit/PowerPC/Processor.cpp +++ b/Private/HALKit/PowerPC/Processor.cpp @@ -1,68 +1,48 @@ /* -* ======================================================== -* -* hCore -* Copyright 2024 Mahrouss Logic, all rights reserved. -* -* ======================================================== -*/ + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ #include <HALKit/PowerPC/Processor.hpp> #include <KernelKit/DebugOutput.hpp> extern "C" void flush_tlb() {} extern "C" void rt_wait_for_io() {} -extern "C" hCore::HAL::StackFrame* rt_get_current_context() { } +extern "C" hCore::HAL::StackFrame* rt_get_current_context() {} -namespace hCore -{ -namespace HAL -{ - UIntPtr hal_create_page(bool rw, bool user) - { - return 0; - } +namespace hCore { +namespace HAL { +UIntPtr hal_create_page(bool rw, bool user) { return 0; } - UIntPtr hal_alloc_page(UIntPtr offset, bool rw, bool user) - { - return 0; - } -} +UIntPtr hal_alloc_page(UIntPtr offset, bool rw, bool user) { return 0; } +} // namespace HAL // @brief wakes up thread. // wakes up thread from hang. -void rt_wakeup_thread(HAL::StackFrame* stack) -{ - -} +void rt_wakeup_thread(HAL::StackFrame* stack) {} // @brief makes thread sleep. // hooks and hangs thread to prevent code from executing. -void rt_hang_thread(HAL::StackFrame* stack) -{ - -} +void rt_hang_thread(HAL::StackFrame* stack) {} // @brief main HAL entrypoint -void init_hal() -{ - -} +void init_hal() {} -void system_io_print(const char *bytes) -{ - if (!bytes) - return; +void system_io_print(const char* bytes) { + if (!bytes) return; - SizeT index = 0; - SizeT len = string_length(bytes, 256); + SizeT index = 0; + SizeT len = string_length(bytes, 256); - while (index < len) - { - // TODO - ++index; - } + while (index < len) { + // TODO + ++index; + } } TerminalDevice kcout(hCore::system_io_print, nullptr); -}
\ No newline at end of file +} // namespace hCore diff --git a/Private/HALKit/PowerPC/Processor.hpp b/Private/HALKit/PowerPC/Processor.hpp index 58de1aa6..5fc0dcb2 100644 --- a/Private/HALKit/PowerPC/Processor.hpp +++ b/Private/HALKit/PowerPC/Processor.hpp @@ -14,37 +14,31 @@ #define __aligned __attribute__((aligned(4))) -namespace hCore::HAL -{ - typedef UIntPtr Reg; - - struct __aligned StackFrame - { - Reg R0; - Reg R1; - Reg R2; - Reg R3; - Reg R4; - Reg R5; - Reg R6; - Reg R7; - Reg ID; // R8 - }; - - typedef StackFrame* StackFramePtr; - - inline void rt_halt() - { - while (1) - {} - } - - inline void rt_cli() - { - - } +namespace hCore::HAL { +typedef UIntPtr Reg; + +struct __aligned StackFrame { + Reg R0; + Reg R1; + Reg R2; + Reg R3; + Reg R4; + Reg R5; + Reg R6; + Reg R7; + Reg ID; // R8 +}; + +typedef StackFrame* StackFramePtr; + +inline void rt_halt() { + while (1) { + } } +inline void rt_cli() {} +} // namespace hCore::HAL + extern "C" void int_handle_math(hCore::UIntPtr sp); extern "C" void int_handle_pf(hCore::UIntPtr sp); -extern "C" void* __ppc_alloca(size_t sz);
\ No newline at end of file +extern "C" void* __ppc_alloca(size_t sz); diff --git a/Private/HALKit/PowerPC/CorePowerPCStart.s b/Private/HALKit/PowerPC/StartSequence.s index f0c5ae2b..0b9807d0 100644 --- a/Private/HALKit/PowerPC/CorePowerPCStart.s +++ b/Private/HALKit/PowerPC/StartSequence.s @@ -3,4 +3,4 @@ .text __AssemblerStart: - b __AssemblerStart
\ No newline at end of file + b __AssemblerStart diff --git a/Private/KernelKit/ProcessManager.hpp b/Private/KernelKit/ProcessManager.hpp index 8f3e04a5..89f94941 100644 --- a/Private/KernelKit/ProcessManager.hpp +++ b/Private/KernelKit/ProcessManager.hpp @@ -13,7 +13,7 @@ #include <ArchKit/Arch.hpp> #include <KernelKit/FileManager.hpp> #include <KernelKit/PermissionSelector.hxx> -#include <NewKit/Heap.hpp> +#include <NewKit/UserHeap.hpp> #include <NewKit/LockDelegate.hpp> #include <NewKit/MutableArray.hpp> diff --git a/Private/NewBoot/Source/HEL/AMD64/Boot.cxx b/Private/NewBoot/Source/HEL/AMD64/Boot.cxx index 96c30c12..70f280e6 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Boot.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Boot.cxx @@ -11,46 +11,43 @@ constexpr hCore::UInt32 kVGABaseAddress = 0xb8000; -hCore::SizeT BStrLen(const char *ptr) -{ - long long int cnt = 0; +hCore::SizeT BStrLen(const char *ptr) { + long long int cnt = 0; - while (*ptr != 0) - { - ++ptr; - ++cnt; - } + while (*ptr != 0) { + ++ptr; + ++cnt; + } - return cnt; + return cnt; } /** @brief puts wrapper over VGA. */ -void BKTextWriter::WriteString(const char *str, unsigned char forecolour, unsigned char backcolour, int x, int y) -{ - if (*str == 0 || !str) - return; - - for (SizeT idx = 0; idx < BStrLen(str); ++idx) - { - this->WriteCharacter(str[idx], forecolour, backcolour, x, y); - ++x; - } +void BKTextWriter::WriteString(const char *str, unsigned char forecolour, + unsigned char backcolour, int x, int y) { + if (*str == 0 || !str) return; + + for (SizeT idx = 0; idx < BStrLen(str); ++idx) { + this->WriteCharacter(str[idx], forecolour, backcolour, x, y); + ++x; + } } /** @brief putc wrapper over VGA. */ -void BKTextWriter::WriteCharacter(char c, unsigned char forecolour, unsigned char backcolour, int x, int y) -{ - UInt16 attrib = (backcolour << 4) | (forecolour & 0x0F); - - // Video Graphics Array - // Reads at kVGABaseAddress - // Decodes UInt16, gets attributes (back colour, fore colour) - // Gets character, send it to video display with according colour in the registry. - - fWhere = (volatile UInt16 *)kVGABaseAddress + (y * 80 + x); - *fWhere = c | (attrib << 8); +void BKTextWriter::WriteCharacter(char c, unsigned char forecolour, + unsigned char backcolour, int x, int y) { + UInt16 attrib = (backcolour << 4) | (forecolour & 0x0F); + + // Video Graphics Array + // Reads at kVGABaseAddress + // Decodes UInt16, gets attributes (back colour, fore colour) + // Gets character, send it to video display with according colour in the + // registry. + + fWhere = (volatile UInt16 *)kVGABaseAddress + (y * 80 + x); + *fWhere = c | (attrib << 8); } diff --git a/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx b/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx index 0102fa8c..0d44086b 100644 --- a/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx @@ -11,16 +11,19 @@ #include <BootKit/Processor.hxx> #include <BootKit/Protocol.hxx> -EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle, EfiSystemTable *SystemTable) -{ - SystemTable->ConOut->OutputString(SystemTable->ConOut, L"HCoreLdr: Starting \\EPM\\HCore...\r\n"); +EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle, + EfiSystemTable *SystemTable) { + SystemTable->ConOut->OutputString(SystemTable->ConOut, + L"HCoreLdr: Starting \\EPM\\HCore...\r\n"); - if (SystemTable->BootServices->ExitBootServices(ImageHandle, kBaseHandoverStruct) != kEfiOk) - { - SystemTable->ConOut->OutputString(SystemTable->ConOut, L"HCoreLdr: Could not Exit UEFI!\r\nHanging...\r\n"); + if (SystemTable->BootServices->ExitBootServices( + ImageHandle, kBaseHandoverStruct) != kEfiOk) { + SystemTable->ConOut->OutputString( + SystemTable->ConOut, + L"HCoreLdr: Could not Exit UEFI!\r\nHanging...\r\n"); - return kEfiFail; - } + return kEfiFail; + } - return kEfiOk; + return kEfiOk; } diff --git a/Private/NewBoot/Source/HEL/AMD64/Processor.cxx b/Private/NewBoot/Source/HEL/AMD64/Processor.cxx index f1f9b617..a0c93ab5 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Processor.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Processor.cxx @@ -16,22 +16,10 @@ #include <BootKit/Processor.hxx> -extern "C" void rt_halt(void) -{ - asm volatile("hlt"); -} +extern "C" void rt_halt(void) { asm volatile("hlt"); } -extern "C" void rt_cli(void) -{ - asm volatile("cli"); -} +extern "C" void rt_cli(void) { asm volatile("cli"); } -extern "C" void rt_sti(void) -{ - asm volatile("sti"); -} +extern "C" void rt_sti(void) { asm volatile("sti"); } -extern "C" void rt_cld(void) -{ - asm volatile("cld"); -} +extern "C" void rt_cld(void) { asm volatile("cld"); } diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 6ccec377..1fa6cc46 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -6,7 +6,7 @@ CC_GNU=x86_64-w64-mingw32-g++ LD_GNU=x86_64-w64-mingw32-ld -FLAG_GNU=-fshort-wchar -fPIC -D__DBG__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I../../efiSDK/inc -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__hCore__ -I./ -I$(HOME)/ +FLAG_GNU=-fshort-wchar -fPIC -D__DBG__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I../../efiSDK/inc -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I./ -I$(HOME)/ .PHONY: arch-amd64 arch-amd64: diff --git a/Private/NewKit/KHeap.hpp b/Private/NewKit/KernelHeap.hpp index 7c9802d7..13037aa1 100644 --- a/Private/NewKit/KHeap.hpp +++ b/Private/NewKit/KernelHeap.hpp @@ -11,13 +11,13 @@ // last-rev 5/03/23 // file: KHeap.hpp -// description: page allocation for kernel. +// description: heap allocation for the kernel. #include <NewKit/Defines.hpp> #include <NewKit/Pmm.hpp> namespace hCore { -Int32 kernel_delete_ptr(voidPtr allocatedPtr); -voidPtr kernel_new_ptr(const SizeT &sz, const bool rw, const bool user); + Int32 kernel_delete_ptr(voidPtr allocatedPtr); + voidPtr kernel_new_ptr(const SizeT &sz, const bool rw, const bool user); } // namespace hCore diff --git a/Private/NewKit/Macros.hpp b/Private/NewKit/Macros.hpp index 8972e7b5..a6cb58dc 100644 --- a/Private/NewKit/Macros.hpp +++ b/Private/NewKit/Macros.hpp @@ -37,9 +37,9 @@ #define ATTRIBUTE(X) __attribute__((X)) #endif // #ifndef ATTRIBUTE -#ifndef __hCore__ -#define __hCore__ (202401) -#endif // !__hCore__ +#ifndef __HCORE__ +#define __HCORE__ (202401) +#endif // !__HCORE__ #ifndef EXTERN_C #define EXTERN_C() \ diff --git a/Private/NewKit/New.hpp b/Private/NewKit/New.hpp index 07939ab6..ba862788 100644 --- a/Private/NewKit/New.hpp +++ b/Private/NewKit/New.hpp @@ -9,7 +9,7 @@ */ #pragma once -#include <NewKit/KHeap.hpp> +#include <NewKit/KernelHeap.hpp> typedef __SIZE_TYPE__ size_t; // gcc will complain about that diff --git a/Private/NewKit/NewKit.hpp b/Private/NewKit/NewKit.hpp index e6797f33..02931085 100644 --- a/Private/NewKit/NewKit.hpp +++ b/Private/NewKit/NewKit.hpp @@ -13,7 +13,7 @@ #include <NewKit/OwnPtr.hpp> #include <NewKit/New.hpp> #include <NewKit/Json.hpp> -#include <NewKit/Heap.hpp> +#include <NewKit/UserHeap.hpp> #include <NewKit/ErrorOr.hpp> #include <NewKit/ArrayList.hpp> #include <NewKit/Array.hpp> diff --git a/Private/NewKit/Heap.hpp b/Private/NewKit/UserHeap.hpp index 71a93f6b..71a93f6b 100644 --- a/Private/NewKit/Heap.hpp +++ b/Private/NewKit/UserHeap.hpp diff --git a/Private/Source/CodeManager.cxx b/Private/Source/CodeManager.cxx index f1c6840e..ced403cc 100644 --- a/Private/Source/CodeManager.cxx +++ b/Private/Source/CodeManager.cxx @@ -14,7 +14,7 @@ #include <KernelKit/FileManager.hpp> #include <KernelKit/ProcessManager.hpp> #include <NewKit/ErrorID.hpp> -#include <NewKit/KHeap.hpp> +#include <NewKit/KernelHeap.hpp> #include <NewKit/OwnPtr.hpp> #include <NewKit/String.hpp> diff --git a/Private/Source/Crc32.cxx b/Private/Source/Crc32.cxx index 72b4da55..37663b8d 100644 --- a/Private/Source/Crc32.cxx +++ b/Private/Source/Crc32.cxx @@ -12,56 +12,67 @@ // @file CRC32.cpp // @brief Checksum implementation. -namespace hCore -{ - UInt kCrcTbl[kCrcCnt] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, - 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, - 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, - 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, - 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, - 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, - 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, - 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, - 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, - 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, - 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, - 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, - 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, - 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, - 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d - }; +namespace hCore { +UInt kCrcTbl[kCrcCnt] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; - static Int crc_byte(Int crc, UChar byte) - { - crc = (crc >> 8) ^ kCrcTbl[(byte) ^ (crc & 0x000000FF)]; // shift 8 bytes to the right - - // XOR polynomial XOR the crc - // without the 2 highest bytes - return crc; - } +static Int crc_byte(Int crc, UChar byte) { + crc = (crc >> 8) ^ + kCrcTbl[(byte) ^ (crc & 0x000000FF)]; // shift 8 bytes to the right - Int crc32(const Char *byte, Int len) - { - Int checksum = 0; + // XOR polynomial XOR the crc + // without the 2 highest bytes + return crc; +} - for (UChar index = 1; index < len; ++index) - checksum = crc_byte(checksum, byte[index]); +Int crc32(const Char *byte, Int len) { + Int checksum = 0; - return checksum; - } -} // namespace hCore + for (UChar index = 1; index < len; ++index) + checksum = crc_byte(checksum, byte[index]); + + return checksum; +} +} // namespace hCore diff --git a/Private/Source/CxxAbi.cxx b/Private/Source/CxxAbi.cxx index 4984c81a..49b5834a 100644 --- a/Private/Source/CxxAbi.cxx +++ b/Private/Source/CxxAbi.cxx @@ -18,98 +18,75 @@ void *__dso_handle; atexit_func_entry_t __atexit_funcs[DSO_MAX_OBJECTS]; uarch_t __atexit_func_count; -extern "C" void __cxa_pure_virtual() -{ - hCore::kcout << "[__cxa_pure_virtual] Placeholder\n"; +extern "C" void __cxa_pure_virtual() { + hCore::kcout << "[__cxa_pure_virtual] Placeholder\n"; } -extern "C" void __stack_chk_fail() -{ - hCore::kcout << "[__stack_chk_fail] Buffer overflow detected\n"; - hCore::panic(RUNTIME_CHECK_POINTER); +extern "C" void __stack_chk_fail() { + hCore::kcout << "[__stack_chk_fail] Buffer overflow detected\n"; + hCore::panic(RUNTIME_CHECK_POINTER); } -extern "C" int __cxa_atexit(void (*f)(void *), void *arg, void *dso) -{ - if (__atexit_func_count >= DSO_MAX_OBJECTS) - return -1; +extern "C" int __cxa_atexit(void (*f)(void *), void *arg, void *dso) { + if (__atexit_func_count >= DSO_MAX_OBJECTS) return -1; - __atexit_funcs[__atexit_func_count].destructor_func = f; - __atexit_funcs[__atexit_func_count].obj_ptr = arg; - __atexit_funcs[__atexit_func_count].dso_handle = dso; + __atexit_funcs[__atexit_func_count].destructor_func = f; + __atexit_funcs[__atexit_func_count].obj_ptr = arg; + __atexit_funcs[__atexit_func_count].dso_handle = dso; - __atexit_func_count++; + __atexit_func_count++; - return 0; + return 0; } -extern "C" void __cxa_finalize(void *f) -{ - uarch_t i = __atexit_func_count; - if (!f) - { - while (i--) - { - if (__atexit_funcs[i].destructor_func) - { - (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); - }; - } - - return; +extern "C" void __cxa_finalize(void *f) { + uarch_t i = __atexit_func_count; + if (!f) { + while (i--) { + if (__atexit_funcs[i].destructor_func) { + (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); + }; } - while (i--) - { - if (__atexit_funcs[i].destructor_func) - { - (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); - __atexit_funcs[i].destructor_func = 0; - }; - } + return; + } + + while (i--) { + if (__atexit_funcs[i].destructor_func) { + (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); + __atexit_funcs[i].destructor_func = 0; + }; + } } -namespace cxxabiv1 -{ - extern "C" int __cxa_guard_acquire(__guard *g) - { - (void) g; - return 0; - } +namespace cxxabiv1 { +extern "C" int __cxa_guard_acquire(__guard *g) { + (void)g; + return 0; +} - extern "C" int __cxa_guard_release(__guard *g) - { - *(char *) g = 1; - return 0; - } +extern "C" int __cxa_guard_release(__guard *g) { + *(char *)g = 1; + return 0; +} - extern "C" void __cxa_guard_abort(__guard *g) - { - (void) g; - } -} // namespace cxxabiv1 +extern "C" void __cxa_guard_abort(__guard *g) { (void)g; } +} // namespace cxxabiv1 #else -namespace cxxkit -{ - extern "C" void __unwind(void(**finis)(void), int cnt) - { - for (int i = 0; i < cnt; ++i) - (finis[i])(); - } +namespace cxxkit { +extern "C" void __unwind(void (**finis)(void), int cnt) { + for (int i = 0; i < cnt; ++i) (finis[i])(); +} - extern "C" void __init_local(void(**init)(void), int cnt) - { - for (int i = 0; i < cnt; ++i) - (init[i])(); - } +extern "C" void __init_local(void (**init)(void), int cnt) { + for (int i = 0; i < cnt; ++i) (init[i])(); +} - extern "C" void __fini_local(void(**finis)(void), int cnt) - { - for (int i = 0; i < cnt; ++i) - (finis[i])(); - } +extern "C" void __fini_local(void (**finis)(void), int cnt) { + for (int i = 0; i < cnt; ++i) (finis[i])(); } +} // namespace cxxkit #endif diff --git a/Private/Source/CxxKitRT.cxx b/Private/Source/CxxKitRT.cxx index 21ebb342..e608ab3c 100644 --- a/Private/Source/CxxKitRT.cxx +++ b/Private/Source/CxxKitRT.cxx @@ -14,35 +14,30 @@ using namespace hCore; // unimplemented _HintTell -void _HintTell(_HintMessage* ppMsg, _HintId* pId) -{ - switch (*pId) - { - case kErrorExecutable: - { - const char* msg = "CodeManager doesn't recognize this executable."; - rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg)); - break; +void _HintTell(_HintMessage* ppMsg, _HintId* pId) { + switch (*pId) { + case kErrorExecutable: { + const char* msg = "CodeManager doesn't recognize this executable."; + rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg)); + break; } - case kErrorExecutableLib: - { - const char* msg = "CodeManager doesn't recognize this library."; - rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg)); - break; + case kErrorExecutableLib: { + const char* msg = "CodeManager doesn't recognize this library."; + rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg)); + break; } - case kErrorFileNotFound: - { - const char* msg = "FileManager doesn't find this file."; - rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg)); - break; + case kErrorFileNotFound: { + const char* msg = "FileManager doesn't find this file."; + rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg)); + break; } - case kErrorNoNetwork: - { - const char* msg = "NetworkManager doesn't detect any WiFi/Ethernet connection."; - rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg)); - break; + case kErrorNoNetwork: { + const char* msg = + "NetworkManager doesn't detect any WiFi/Ethernet connection."; + rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg)); + break; } default: - break; - } -}
\ No newline at end of file + break; + } +} diff --git a/Private/Source/Defines.cxx b/Private/Source/Defines.cxx index 5b78388f..3e0bd946 100644 --- a/Private/Source/Defines.cxx +++ b/Private/Source/Defines.cxx @@ -8,4 +8,3 @@ */ #include <NewKit/Defines.hpp> - diff --git a/Private/Source/DriveManager.cxx b/Private/Source/DriveManager.cxx index be35e275..ee279ed1 100644 --- a/Private/Source/DriveManager.cxx +++ b/Private/Source/DriveManager.cxx @@ -10,53 +10,43 @@ #include <KernelKit/DebugOutput.hpp> #include <KernelKit/DriveManager.hpp> -namespace hCore -{ -DriveSelector::DriveSelector() : fDrive(nullptr) -{ -} +namespace hCore { +DriveSelector::DriveSelector() : fDrive(nullptr) {} -DriveSelector::~DriveSelector() -{ - if (fDrive) - { - this->Unmount(); - } +DriveSelector::~DriveSelector() { + if (fDrive) { + this->Unmount(); + } } -DriveTraits &DriveSelector::GetMounted() -{ - MUST_PASS(fDrive != nullptr); - return *fDrive; +DriveTraits &DriveSelector::GetMounted() { + MUST_PASS(fDrive != nullptr); + return *fDrive; } -bool DriveSelector::Mount(DriveTraits *drive) -{ - if (drive && drive->fReady() && fDrive == nullptr) - { - fDrive = drive; - fDrive->fMount(); +bool DriveSelector::Mount(DriveTraits *drive) { + if (drive && drive->fReady() && fDrive == nullptr) { + fDrive = drive; + fDrive->fMount(); - kcout << "[Mount] drive: " << fDrive->fName << "\n"; + kcout << "[Mount] drive: " << fDrive->fName << "\n"; - return true; - } + return true; + } - return false; + return false; } -DriveTraits *DriveSelector::Unmount() -{ - if (!fDrive) - return nullptr; +DriveTraits *DriveSelector::Unmount() { + if (!fDrive) return nullptr; - auto drivePointer = fDrive; + auto drivePointer = fDrive; - fDrive->fUnmount(); - fDrive = nullptr; + fDrive->fUnmount(); + fDrive = nullptr; - kcout << "[Unmount] drive: " << drivePointer->fName << "\n"; + kcout << "[Unmount] drive: " << drivePointer->fName << "\n"; - return drivePointer; + return drivePointer; } -} // namespace hCore +} // namespace hCore diff --git a/Private/Source/ErrorOr.cxx b/Private/Source/ErrorOr.cxx index cf6f2317..4137c243 100644 --- a/Private/Source/ErrorOr.cxx +++ b/Private/Source/ErrorOr.cxx @@ -9,4 +9,4 @@ #include <NewKit/ErrorOr.hpp> -/* BUILDME needs that file */
\ No newline at end of file +/* BUILDME needs that file */ diff --git a/Private/Source/FileManager.cxx b/Private/Source/FileManager.cxx index 2a6648ce..9bf26c29 100644 --- a/Private/Source/FileManager.cxx +++ b/Private/Source/FileManager.cxx @@ -13,35 +13,30 @@ //! @brief File manager for hCore. -namespace hCore -{ - static IFilesystemManager* kMounted = nullptr; - - /// @brief FilesystemManager getter. - /// @return The mounted filesystem. - IFilesystemManager* IFilesystemManager::GetMounted() { return kMounted; } - - IFilesystemManager* IFilesystemManager::Unmount() - { - if (kMounted) - { - auto mount = kMounted; - kMounted = nullptr; - - return mount; - } - - return nullptr; - } - - bool IFilesystemManager::Mount(IFilesystemManager* pMount) - { - if (pMount) - { - kMounted = pMount; - return true; - } - - return false; - } +namespace hCore { +static IFilesystemManager* kMounted = nullptr; + +/// @brief FilesystemManager getter. +/// @return The mounted filesystem. +IFilesystemManager* IFilesystemManager::GetMounted() { return kMounted; } + +IFilesystemManager* IFilesystemManager::Unmount() { + if (kMounted) { + auto mount = kMounted; + kMounted = nullptr; + + return mount; + } + + return nullptr; +} + +bool IFilesystemManager::Mount(IFilesystemManager* pMount) { + if (pMount) { + kMounted = pMount; + return true; + } + + return false; } +} // namespace hCore diff --git a/Private/Source/Framebuffer.cxx b/Private/Source/Framebuffer.cxx index 208e90e9..1a73e449 100644 --- a/Private/Source/Framebuffer.cxx +++ b/Private/Source/Framebuffer.cxx @@ -9,31 +9,28 @@ #include <KernelKit/Framebuffer.hpp> -namespace hCore -{ - Framebuffer::Framebuffer(hCore::Ref<FramebufferContext*> &addr) - : m_FrameBufferAddr(addr), m_Colour(FramebufferColorKind::RGB32) - {} +namespace hCore { +Framebuffer::Framebuffer(hCore::Ref<FramebufferContext*>& addr) + : m_FrameBufferAddr(addr), m_Colour(FramebufferColorKind::RGB32) {} - Framebuffer::~Framebuffer() = default; +Framebuffer::~Framebuffer() = default; - volatile UIntPtr* Framebuffer::operator[](const UIntPtr& width_and_height) - { - if (m_FrameBufferAddr) - return reinterpret_cast<volatile hCore::UIntPtr*>(m_FrameBufferAddr->m_Base + width_and_height); +volatile UIntPtr* Framebuffer::operator[](const UIntPtr& width_and_height) { + if (m_FrameBufferAddr) + return reinterpret_cast<volatile hCore::UIntPtr*>( + m_FrameBufferAddr->m_Base + width_and_height); - return nullptr; - } + return nullptr; +} - Ref<FramebufferContext*>& Framebuffer::Leak() { return m_FrameBufferAddr; } +Ref<FramebufferContext*>& Framebuffer::Leak() { return m_FrameBufferAddr; } - Framebuffer::operator bool() { return m_FrameBufferAddr; } +Framebuffer::operator bool() { return m_FrameBufferAddr; } - const FramebufferColorKind& Framebuffer::Color(const FramebufferColorKind& colour) - { - if (colour != FramebufferColorKind::INVALID) - m_Colour = colour; +const FramebufferColorKind& Framebuffer::Color( + const FramebufferColorKind& colour) { + if (colour != FramebufferColorKind::INVALID) m_Colour = colour; - return m_Colour; - } -} // namespace hCore + return m_Colour; +} +} // namespace hCore diff --git a/Private/Source/GUIDWizard.cxx b/Private/Source/GUIDWizard.cxx index 25875671..d3b11b0a 100644 --- a/Private/Source/GUIDWizard.cxx +++ b/Private/Source/GUIDWizard.cxx @@ -16,49 +16,42 @@ // @brief Size of UUID. #define kUUIDSize 32 -namespace hCore::XRN::Version1 -{ - auto make_sequence(const ArrayList<UShort>& uuidSeq) -> Ref<GUIDSequence*> - { - GUIDSequence *seq = new GUIDSequence(); - MUST_PASS(seq); +namespace hCore::XRN::Version1 { +auto make_sequence(const ArrayList<UShort>& uuidSeq) -> Ref<GUIDSequence*> { + GUIDSequence* seq = new GUIDSequence(); + MUST_PASS(seq); - Ref<GUIDSequence*> sequenceReference{seq, true}; + Ref<GUIDSequence*> sequenceReference{seq, true}; - sequenceReference->m_Ms1 |= uuidSeq[0]; - sequenceReference->m_Ms2 |= uuidSeq[1]; - sequenceReference->m_Ms3 |= uuidSeq[2]; - sequenceReference->m_Ms3 |= uuidSeq[3]; + sequenceReference->m_Ms1 |= uuidSeq[0]; + sequenceReference->m_Ms2 |= uuidSeq[1]; + sequenceReference->m_Ms3 |= uuidSeq[2]; + sequenceReference->m_Ms3 |= uuidSeq[3]; - return sequenceReference; - } + return sequenceReference; +} - // @brief Tries to make a guid out of a string. - // This function is not complete for now - auto try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr <Ref<StringView>> - { - Char buf[kUUIDSize]; +// @brief Tries to make a guid out of a string. +// This function is not complete for now +auto try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<StringView>> { + Char buf[kUUIDSize]; - for (SizeT index = 0; index < 16; ++index) - { - buf[index] = seq->u8[index] + kAsciiBegin; - } + for (SizeT index = 0; index < 16; ++index) { + buf[index] = seq->u8[index] + kAsciiBegin; + } - for (SizeT index = 16; index < 24; ++index) - { - buf[index] = seq->u16[index] + kAsciiBegin; - } + for (SizeT index = 16; index < 24; ++index) { + buf[index] = seq->u16[index] + kAsciiBegin; + } - for (SizeT index = 24; index < 28; ++index) - { - buf[index] = seq->u32[index] + kAsciiBegin; - } + for (SizeT index = 24; index < 28; ++index) { + buf[index] = seq->u32[index] + kAsciiBegin; + } - auto view = StringBuilder::Construct(buf); + auto view = StringBuilder::Construct(buf); - if (view) - return ErrorOr<Ref<StringView>>{ view.Leak() }; + if (view) return ErrorOr<Ref<StringView>>{view.Leak()}; - return ErrorOr<Ref<StringView>>{-1}; - } -} // namespace hCore::XRN::Version1 + return ErrorOr<Ref<StringView>>{-1}; +} +} // namespace hCore::XRN::Version1 diff --git a/Private/Source/GUIDWrapper.cxx b/Private/Source/GUIDWrapper.cxx index 3ae42eeb..fa9a52a6 100644 --- a/Private/Source/GUIDWrapper.cxx +++ b/Private/Source/GUIDWrapper.cxx @@ -9,7 +9,4 @@ #include <CFKit/GUIDWrapper.hpp> -namespace hCore::XRN -{ - -} +namespace hCore::XRN {} diff --git a/Private/Source/Heap.cxx b/Private/Source/Heap.cxx deleted file mode 100644 index ea667a5c..00000000 --- a/Private/Source/Heap.cxx +++ /dev/null @@ -1,208 +0,0 @@ -/* - * ======================================================== - * - * hCore - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include <NewKit/Heap.hpp> -#include <NewKit/PageManager.hpp> - -/// @file Heap.cxx -/// @brief hCore Process Heap Manager -/// @note if you want to look at kernel allocs, please look for KHeap.cxx -/// bugs: 0 - -namespace hCore -{ - class HeapManager final - { - public: - static SizeT& GetCount() { return s_NumPools; } - static Ref<Pmm>& GetPmm() { return s_Pmm; } - static Boolean& IsEnabled() { return s_PoolsAreEnabled; } - static Array<Ref<PTEWrapper*>, kPoolMaxSz>& The() { return s_Pool; } - - private: - static Size s_NumPools; - static Ref<Pmm> s_Pmm; - - private: - static Boolean s_PoolsAreEnabled; - static Array<Ref<PTEWrapper*>, kPoolMaxSz> s_Pool; - - }; - - //! declare fields - - SizeT HeapManager::s_NumPools = 0UL; - Ref<Pmm> HeapManager::s_Pmm; - Boolean HeapManager::s_PoolsAreEnabled = true; - Array<Ref<PTEWrapper*>, kPoolMaxSz> HeapManager::s_Pool; - - static voidPtr rt_find_unused_heap(Int flags); - static void rt_free_heap_internal(voidPtr vaddr); - static voidPtr rt_make_heap(voidPtr vaddr, Int flags); - static bool rt_check_and_free_heap(const SizeT &index, voidPtr ptr); - - static voidPtr rt_find_unused_heap(Int flags) - { - for (SizeT index = 0; index < kPoolMaxSz; ++index) - { - if (HeapManager::The()[index] && - !HeapManager::The()[index].Leak().Leak().Leak()->Present()) - { - HeapManager::GetPmm().Leak().TogglePresent(HeapManager::The()[index].Leak().Leak(), true); - kcout << "[rt_find_unused_heap] Done, trying now to make a pool\r\n"; - - return rt_make_heap((voidPtr)HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress(), flags); - } - } - - return nullptr; - } - - static voidPtr rt_make_heap(voidPtr virtualAddress, Int flags) - { - if (virtualAddress) - { - HeapHeader* pool_hdr = reinterpret_cast<HeapHeader*>(virtualAddress); - - if (!pool_hdr->Free) - { - kcout << "[rt_make_heap] pool_hdr->Free, Pool already exists\n"; - return nullptr; - } - - pool_hdr->Flags = flags; - pool_hdr->Magic = kPoolMag; - pool_hdr->Free = false; - - kcout << "[rt_make_heap] New allocation has been done.\n"; - return reinterpret_cast<voidPtr>((reinterpret_cast<UIntPtr>(virtualAddress) + sizeof(HeapHeader))); - } - - kcout << "[rt_make_heap] Address is invalid"; - return nullptr; - } - - static void rt_free_heap_internal(voidPtr virtualAddress) - { - HeapHeader* pool_hdr = reinterpret_cast<HeapHeader*>(reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(HeapHeader)); - - if (pool_hdr->Magic == kPoolMag) - { - pool_hdr->Free = false; - pool_hdr->Flags = 0; - - kcout << "[rt_free_heap_internal] Successfully marked header as free!\r\n"; - } - } - - static bool rt_check_and_free_heap(const SizeT& index, voidPtr ptr) - { - if (HeapManager::The()[index]) - { - // ErrorOr<>::operator bool - if (!HeapManager::The()[index].Leak().Leak().IsStrong()) - { - // we want them to be weak - // because we allocated it. - if (HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress() == (UIntPtr) ptr) - { - HeapManager::GetPmm().Leak().FreePage(HeapManager::The()[index].Leak().Leak()); - --HeapManager::GetCount(); - - rt_free_heap_internal(ptr); - ptr = nullptr; - - return true; - } - } - } - - return false; - } - - /// @brief Creates a new pool pointer. - /// @param flags the flags attached to it. - /// @return a pool pointer with selected permissions. - voidPtr pool_new_ptr(Int32 flags) - { - if (!HeapManager::IsEnabled()) - return nullptr; - - if (HeapManager::GetCount() > kPoolMaxSz) - return nullptr; - - if (voidPtr ret = rt_find_unused_heap(flags)) - return ret; - - // this wasn't set to true - auto ref_page = HeapManager::GetPmm().Leak().RequestPage(((flags & kPoolUser)), - (flags & kPoolRw)); - if (ref_page) - { - ///! reserve page. - HeapManager::The()[HeapManager::GetCount()].Leak() = ref_page; - auto& ref = HeapManager::GetCount(); - ++ref; // increment the number of addresses we have now. - - kcout << "[pool_new_ptr] New Address found!\r\n"; - - // finally make the pool address. - return rt_make_heap(reinterpret_cast<voidPtr>(ref_page.Leak()->VirtualAddress()), flags); - } - - return nullptr; - } - - /// @brief free a pool pointer. - /// @param ptr The pool pointer to free. - /// @return status code - Int32 pool_free_ptr(voidPtr ptr) - { - if (!HeapManager::IsEnabled()) - return -1; - - if (ptr) - { - SizeT base = HeapManager::GetCount(); - - if (rt_check_and_free_heap(base, ptr)) - return 0; - - for (SizeT index = 0; index < kPoolMaxSz; ++index) - { - if (rt_check_and_free_heap(index, ptr)) - return 0; - - --base; - } - } - - return -1; - } - - /// @brief Checks if pointer is valid. - /// @param thePool the pool pointer. - /// @param thePtr the pointer. - /// @param theLimit the last address of the pool. - /// @return if it is valid. - Boolean pool_ptr_exists(UIntPtr thePool, UIntPtr thePtr, SizeT theLimit) - { - if (HeapManager::GetCount() < 1) - return false; - - if (thePool == 0 || - thePtr == 0 || - theLimit == 0) - { - return false; - } - - return ((thePool) < (thePtr) < (theLimit)); - } -} // namespace hCore diff --git a/Private/Source/IndexableProperty.cxx b/Private/Source/IndexableProperty.cxx index 5b49d6c1..2dac5a09 100644 --- a/Private/Source/IndexableProperty.cxx +++ b/Private/Source/IndexableProperty.cxx @@ -9,20 +9,18 @@ //! @brief hCore NewFS Indexer. -#include <FSKit/IndexableProperty.hxx> #include <CompilerKit/Compiler.hpp> +#include <FSKit/IndexableProperty.hxx> #include <NewKit/MutableArray.hpp> #include <NewKit/Utils.hpp> #define kMaxLenIndexer 256 -namespace hCore -{ - namespace Indexer - { - IndexProperty& IndexableProperty::LeakProperty() noexcept { return fIndex; } +namespace hCore { +namespace Indexer { +IndexProperty& IndexableProperty::LeakProperty() noexcept { return fIndex; } - void IndexableProperty::AddFlag(Int16 flag) { fFlags |= flag; } - void IndexableProperty::RemoveFlag(Int16 flag) { fFlags &= flag; } - } -} +void IndexableProperty::AddFlag(Int16 flag) { fFlags |= flag; } +void IndexableProperty::RemoveFlag(Int16 flag) { fFlags &= flag; } +} // namespace Indexer +} // namespace hCore diff --git a/Private/Source/KHeap.cxx b/Private/Source/KHeap.cxx deleted file mode 100644 index c36c6ad7..00000000 --- a/Private/Source/KHeap.cxx +++ /dev/null @@ -1,126 +0,0 @@ -/* - * ======================================================== - * - * hCore - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include <NewKit/KHeap.hpp> - -//! @file KHeap.cpp -//! @brief this allocator is used by kernel to allocate pages. - -#define kMaxWrappers (4096 * 8) - -namespace hCore -{ -static Ref<PTEWrapper *> kWrapperList[kMaxWrappers]; -static SizeT kWrapperCount = 0UL; -static Ref<PTEWrapper *> kLastWrapper; -static Pmm kPmm; - -namespace Detail -{ -static voidPtr find_ptr(const SizeT &sz, const bool rw, const bool user) -{ - for (SizeT indexWrapper = 0; indexWrapper < kMaxWrappers; ++indexWrapper) - { - if (!kWrapperList[indexWrapper]->Present()) - { - kWrapperList[indexWrapper]->Reclaim(); /* very straight-forward as you can see. */ - return reinterpret_cast<voidPtr>(kWrapperList[indexWrapper]->VirtualAddress()); - } - } - - return nullptr; -} -} // namespace Detail - -/// @brief manual allocation -/// @param sz size of pointer -/// @param rw read write (true to enable it) -/// @param user is it accesible by user processes? -/// @return the pointer -VoidPtr kernel_new_ptr(const SizeT &sz, const bool rw, const bool user) -{ - if (kWrapperCount < sz) - return nullptr; - - if (auto ptr = Detail::find_ptr(sz, rw, user); ptr) - return ptr; - - Ref<PTEWrapper *> wrapper = kPmm.RequestPage(user, rw); - - if (wrapper) - { - kLastWrapper = wrapper; - - kWrapperList[kWrapperCount] = wrapper; - ++kWrapperCount; - - return reinterpret_cast<voidPtr>(wrapper->VirtualAddress()); - } - - return nullptr; -} - -/// @brief Declare pointer as free. -/// @param ptr the pointer. -/// @return -Int32 kernel_delete_ptr(voidPtr ptr) -{ - if (ptr) - { - const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr); - - if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) - { - return kPmm.FreePage(kLastWrapper); - } - - Ref<PTEWrapper *> wrapper; - - for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) - { - if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) - { - wrapper = kWrapperList[indexWrapper]; - return kPmm.FreePage(wrapper); - } - } - } - - return -1; -} - -/// @brief find pointer in kernel heap -/// @param ptr the pointer -/// @return if it exists. -Boolean kernel_valid_ptr(voidPtr ptr) -{ - if (ptr) - { - const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr); - - if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) - { - return true; - } - - Ref<PTEWrapper *> wrapper; - - for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) - { - if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) - { - wrapper = kWrapperList[indexWrapper]; - return true; - } - } - } - - return false; -} -} // namespace hCore diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx new file mode 100644 index 00000000..02688a2f --- /dev/null +++ b/Private/Source/KernelHeap.cxx @@ -0,0 +1,109 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include <NewKit/KernelHeap.hpp> + +//! @file KernelHeap.cpp +//! @brief Kernel allocator. + +#define kMaxWrappers (4096 * 8) + +namespace hCore { +static Ref<PTEWrapper *> kWrapperList[kMaxWrappers]; +static SizeT kWrapperCount = 0UL; +static Ref<PTEWrapper *> kLastWrapper; +static Pmm kPmm; + +namespace Detail { +static voidPtr find_ptr(const SizeT &sz, const bool rw, const bool user) { + for (SizeT indexWrapper = 0; indexWrapper < kMaxWrappers; ++indexWrapper) { + if (!kWrapperList[indexWrapper]->Present()) { + kWrapperList[indexWrapper] + ->Reclaim(); /* very straight-forward as you can see. */ + return reinterpret_cast<voidPtr>( + kWrapperList[indexWrapper]->VirtualAddress()); + } + } + + return nullptr; +} +} // namespace Detail + +/// @brief manual allocation +/// @param sz size of pointer +/// @param rw read write (true to enable it) +/// @param user is it accesible by user processes? +/// @return the pointer +VoidPtr kernel_new_ptr(const SizeT &sz, const bool rw, const bool user) { + if (kWrapperCount < sz) return nullptr; + + if (auto ptr = Detail::find_ptr(sz, rw, user); ptr) return ptr; + + Ref<PTEWrapper *> wrapper = kPmm.RequestPage(user, rw); + + if (wrapper) { + kLastWrapper = wrapper; + + kWrapperList[kWrapperCount] = wrapper; + ++kWrapperCount; + + return reinterpret_cast<voidPtr>(wrapper->VirtualAddress()); + } + + return nullptr; +} + +/// @brief Declare pointer as free. +/// @param ptr the pointer. +/// @return +Int32 kernel_delete_ptr(voidPtr ptr) { + if (ptr) { + const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr); + + if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) { + return kPmm.FreePage(kLastWrapper); + } + + Ref<PTEWrapper *> wrapper; + + for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) { + if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) { + wrapper = kWrapperList[indexWrapper]; + return kPmm.FreePage(wrapper); + } + } + } + + return -1; +} + +/// @brief find pointer in kernel heap +/// @param ptr the pointer +/// @return if it exists. +Boolean kernel_valid_ptr(voidPtr ptr) { + if (ptr) { + const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr); + + if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) { + return true; + } + + Ref<PTEWrapper *> wrapper; + + for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) { + if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) { + wrapper = kWrapperList[indexWrapper]; + return true; + } + } + } + + return false; +} +} // namespace hCore diff --git a/Private/Source/LockDelegate.cxx b/Private/Source/LockDelegate.cxx index 7bc742ec..d6608e60 100644 --- a/Private/Source/LockDelegate.cxx +++ b/Private/Source/LockDelegate.cxx @@ -7,4 +7,4 @@ * ======================================================== */ -#include <NewKit/LockDelegate.hpp>
\ No newline at end of file +#include <NewKit/LockDelegate.hpp> diff --git a/Private/Source/Network/IP.cpp b/Private/Source/Network/IP.cpp index ba6fd71f..4e8f602a 100644 --- a/Private/Source/Network/IP.cpp +++ b/Private/Source/Network/IP.cpp @@ -10,118 +10,86 @@ #include <NetworkKit/IP.hpp> #include <NewKit/Utils.hpp> -namespace hCore -{ - char* RawIPAddress::Address() - { - return m_Addr; - } +namespace hCore { +char* RawIPAddress::Address() { return m_Addr; } - RawIPAddress::RawIPAddress(char bytes[4]) - { - rt_copy_memory(bytes, m_Addr, 4); - } +RawIPAddress::RawIPAddress(char bytes[4]) { rt_copy_memory(bytes, m_Addr, 4); } - bool RawIPAddress::operator==(const RawIPAddress& ipv4) - { - for (Size index = 0; index < 4; ++index) - { - if (ipv4.m_Addr[index] != m_Addr[index]) - return false; - } +bool RawIPAddress::operator==(const RawIPAddress& ipv4) { + for (Size index = 0; index < 4; ++index) { + if (ipv4.m_Addr[index] != m_Addr[index]) return false; + } - return true; - } + return true; +} - bool RawIPAddress::operator!=(const RawIPAddress& ipv4) - { - for (Size index = 0; index < 4; ++index) - { - if (ipv4.m_Addr[index] == m_Addr[index]) - return false; - } +bool RawIPAddress::operator!=(const RawIPAddress& ipv4) { + for (Size index = 0; index < 4; ++index) { + if (ipv4.m_Addr[index] == m_Addr[index]) return false; + } - return true; - } + return true; +} - char& RawIPAddress::operator[](const Size& index) - { - kcout << "[RawIPAddress::operator[]] Fetching Index...\r\n"; +char& RawIPAddress::operator[](const Size& index) { + kcout << "[RawIPAddress::operator[]] Fetching Index...\r\n"; - if (index > 4) - panic(RUNTIME_CHECK_EXPRESSION); + if (index > 4) panic(RUNTIME_CHECK_EXPRESSION); - return m_Addr[index]; - } + return m_Addr[index]; +} - RawIPAddress6::RawIPAddress6(char bytes[8]) - { - rt_copy_memory(bytes, m_Addr, 8); - } +RawIPAddress6::RawIPAddress6(char bytes[8]) { + rt_copy_memory(bytes, m_Addr, 8); +} - char &RawIPAddress6::operator[](const Size &index) - { - kcout << "[RawIPAddress6::operator[]] Fetching Index...\r\n"; +char& RawIPAddress6::operator[](const Size& index) { + kcout << "[RawIPAddress6::operator[]] Fetching Index...\r\n"; - if (index > 8) - panic(RUNTIME_CHECK_EXPRESSION); + if (index > 8) panic(RUNTIME_CHECK_EXPRESSION); - return m_Addr[index]; - } + return m_Addr[index]; +} - bool RawIPAddress6::operator==(const RawIPAddress6& ipv6) - { - for (SizeT index = 0; index < 8; ++index) - { - if (ipv6.m_Addr[index] != m_Addr[index]) - return false; - } +bool RawIPAddress6::operator==(const RawIPAddress6& ipv6) { + for (SizeT index = 0; index < 8; ++index) { + if (ipv6.m_Addr[index] != m_Addr[index]) return false; + } - return true; - } + return true; +} - bool RawIPAddress6::operator!=(const RawIPAddress6& ipv6) - { - for (SizeT index = 0; index < 8; ++index) - { - if (ipv6.m_Addr[index] == m_Addr[index]) - return false; - } +bool RawIPAddress6::operator!=(const RawIPAddress6& ipv6) { + for (SizeT index = 0; index < 8; ++index) { + if (ipv6.m_Addr[index] == m_Addr[index]) return false; + } - return true; - } + return true; +} - ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress6> ipv6) - { - auto str = StringBuilder::Construct(ipv6.Leak().Address()); - return str; - } +ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress6> ipv6) { + auto str = StringBuilder::Construct(ipv6.Leak().Address()); + return str; +} - ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress> ipv4) - { - auto str = StringBuilder::Construct(ipv4.Leak().Address()); - return str; - } +ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress> ipv4) { + auto str = StringBuilder::Construct(ipv4.Leak().Address()); + return str; +} - bool IPFactory::IpCheckVersion4(const char *ip) - { - int cnter = 0; - - for (Size base = 0; base < string_length(ip); ++base) - { - if (ip[base] == '.') - { - cnter = 0; - } - else - { - if (cnter == 3) - return false; - - ++cnter; - } - } - - return true; +bool IPFactory::IpCheckVersion4(const char* ip) { + int cnter = 0; + + for (Size base = 0; base < string_length(ip); ++base) { + if (ip[base] == '.') { + cnter = 0; + } else { + if (cnter == 3) return false; + + ++cnter; } -} // namespace NewKit + } + + return true; +} +} // namespace hCore diff --git a/Private/Source/Network/NetworkDevice.cpp b/Private/Source/Network/NetworkDevice.cpp index 766e1f2e..bd75d7ed 100644 --- a/Private/Source/Network/NetworkDevice.cpp +++ b/Private/Source/Network/NetworkDevice.cpp @@ -12,23 +12,21 @@ // network devices implementation. // PPPNetworkService, TCPNetworkDevice, UDPNetworkService -namespace hCore -{ - NetworkDevice::NetworkDevice(void (*out)(NetworkDeviceCommand), void (*in)(NetworkDeviceCommand), void(*on_cleanup)(void)) - : DeviceInterface<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup) - { +namespace hCore { +NetworkDevice::NetworkDevice(void (*out)(NetworkDeviceCommand), + void (*in)(NetworkDeviceCommand), + void (*on_cleanup)(void)) + : DeviceInterface<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup) { #ifdef __DEBUG__ - kcout << "NetworkDevice init.\r\n"; + kcout << "NetworkDevice init.\r\n"; #endif - } +} - NetworkDevice::~NetworkDevice() - { +NetworkDevice::~NetworkDevice() { #ifdef __DEBUG__ - kcout << "NetworkDevice cleanup.\r\n"; + kcout << "NetworkDevice cleanup.\r\n"; #endif - if (fCleanup) - fCleanup(); - } -} // namespace NewKit + if (fCleanup) fCleanup(); +} +} // namespace hCore diff --git a/Private/Source/New+Delete.cxx b/Private/Source/New+Delete.cxx index ff2bf8bb..0e247e0c 100644 --- a/Private/Source/New+Delete.cxx +++ b/Private/Source/New+Delete.cxx @@ -7,7 +7,7 @@ * ======================================================== */ -#include <NewKit/KHeap.hpp> +#include <NewKit/KernelHeap.hpp> #include <NewKit/New.hpp> void* operator new[](size_t sz) diff --git a/Private/Source/NewFS-Journal.cxx b/Private/Source/NewFS-Journal.cxx index 9c96928d..14ba417f 100644 --- a/Private/Source/NewFS-Journal.cxx +++ b/Private/Source/NewFS-Journal.cxx @@ -14,54 +14,46 @@ #define kOpCache (4) -namespace hCore -{ - typedef Boolean(*NewFSRunner)(VoidPtr delegate); - - class NewFSJournalRunner final - { - public: - NewFSRunner fLoadRoutine{ nullptr }; - NewFSRunner fCacheRoutine{ nullptr }; - NewFSRunner fUnloadRoutine{ nullptr }; - - explicit NewFSJournalRunner(NewFSRunner load_runner) - : fLoadRoutine(load_runner) - { - MUST_PASS(fLoadRoutine); - - fLoadRoutine(this); - } - - ~NewFSJournalRunner() noexcept - { - MUST_PASS(fUnloadRoutine); - - fUnloadRoutine(this); - } - - HCORE_COPY_DEFAULT(NewFSJournalRunner); - - public: - Boolean Run(const Int32& operation, VoidPtr class_ptr) - { - switch (operation) - { - case kOpCache: - { - if (!class_ptr) - { - kcout << "Miss for class_ptr at NewFSJournalManager::Run(class_ptr) " << __FILE__ << "\n"; - return false; - } +namespace hCore { +typedef Boolean (*NewFSRunner)(VoidPtr delegate); - MUST_PASS(fCacheRoutine); - return fCacheRoutine(class_ptr); - } - }; - - return false; - } - +class NewFSJournalRunner final { + public: + NewFSRunner fLoadRoutine{nullptr}; + NewFSRunner fCacheRoutine{nullptr}; + NewFSRunner fUnloadRoutine{nullptr}; + + explicit NewFSJournalRunner(NewFSRunner load_runner) + : fLoadRoutine(load_runner) { + MUST_PASS(fLoadRoutine); + + fLoadRoutine(this); + } + + ~NewFSJournalRunner() noexcept { + MUST_PASS(fUnloadRoutine); + + fUnloadRoutine(this); + } + + HCORE_COPY_DEFAULT(NewFSJournalRunner); + + public: + Boolean Run(const Int32& operation, VoidPtr class_ptr) { + switch (operation) { + case kOpCache: { + if (!class_ptr) { + kcout << "Miss for class_ptr at NewFSJournalManager::Run(class_ptr) " + << __FILE__ << "\n"; + return false; + } + + MUST_PASS(fCacheRoutine); + return fCacheRoutine(class_ptr); + } }; -} // namespace hCore + + return false; + } +}; +} // namespace hCore diff --git a/Private/Source/NewFS.cxx b/Private/Source/NewFS.cxx index cd787e9b..2283e779 100644 --- a/Private/Source/NewFS.cxx +++ b/Private/Source/NewFS.cxx @@ -10,42 +10,34 @@ #include <FSKit/NewFS.hxx> #include <KernelKit/FileManager.hpp> -namespace hCore -{ - NewFilesystemManager::NewFilesystemManager() = default; - - NewFilesystemManager::~NewFilesystemManager() = default; - - /** - * Unallocates a file from disk. - * @param node_name it's path. - * @return operation status boolean. - */ - bool NewFilesystemManager::Remove(const char* node_name) - { - if (node_name == nullptr || - *node_name == 0) - return false; - - if (auto catalog = fIO->GetCatalog(node_name); - catalog) - return fIO->RemoveCatalog(*catalog); - - return false; - } - - NodePtr NewFilesystemManager::Create(const char* path) - { - return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindFile)); - } - - NodePtr NewFilesystemManager::CreateDirectory(const char *path) - { - return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindDir)); - } - - NodePtr NewFilesystemManager::CreateAlias(const char *path) - { - return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindAlias)); - } -} // namespace hCore +namespace hCore { +NewFilesystemManager::NewFilesystemManager() = default; + +NewFilesystemManager::~NewFilesystemManager() = default; + +/** + * Unallocates a file from disk. + * @param node_name it's path. + * @return operation status boolean. + */ +bool NewFilesystemManager::Remove(const char* node_name) { + if (node_name == nullptr || *node_name == 0) return false; + + if (auto catalog = fIO->GetCatalog(node_name); catalog) + return fIO->RemoveCatalog(*catalog); + + return false; +} + +NodePtr NewFilesystemManager::Create(const char* path) { + return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindFile)); +} + +NodePtr NewFilesystemManager::CreateDirectory(const char* path) { + return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindDir)); +} + +NodePtr NewFilesystemManager::CreateAlias(const char* path) { + return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindAlias)); +} +} // namespace hCore diff --git a/Private/Source/OSErr.cxx b/Private/Source/OSErr.cxx index 810b77b7..6c37c40d 100644 --- a/Private/Source/OSErr.cxx +++ b/Private/Source/OSErr.cxx @@ -8,4 +8,3 @@ */ #include <KernelKit/OSErr.hpp> - diff --git a/Private/Source/OwnPtr.cxx b/Private/Source/OwnPtr.cxx index 79a9a368..f7f9d31f 100644 --- a/Private/Source/OwnPtr.cxx +++ b/Private/Source/OwnPtr.cxx @@ -7,4 +7,4 @@ * ======================================================== */ -#include <NewKit/OwnPtr.hpp>
\ No newline at end of file +#include <NewKit/OwnPtr.hpp> diff --git a/Private/Source/PRDT.cxx b/Private/Source/PRDT.cxx index 7e74c200..8ea2ee70 100644 --- a/Private/Source/PRDT.cxx +++ b/Private/Source/PRDT.cxx @@ -8,42 +8,28 @@ */ #include <KernelKit/DebugOutput.hpp> -#include <StorageKit/PRDT.hpp> #include <NewKit/String.hpp> +#include <StorageKit/PRDT.hpp> -namespace hCore -{ - PRDT::PRDT(const UIntPtr &physAddr) - : m_PrdtAddr(physAddr) - { - MUST_PASS(physAddr); - kcout << "PRDT::PRDT() {}\r\n"; - } +namespace hCore { +PRDT::PRDT(const UIntPtr& physAddr) : m_PrdtAddr(physAddr) { + MUST_PASS(physAddr); + kcout << "PRDT::PRDT() {}\r\n"; +} - PRDT::~PRDT() - { - kcout << "PRDT::~PRDT() {}\r\n"; - m_PrdtAddr = 0; - } +PRDT::~PRDT() { + kcout << "PRDT::~PRDT() {}\r\n"; + m_PrdtAddr = 0; +} - const UInt& PRDT::Low() - { - return m_Low; - } +const UInt& PRDT::Low() { return m_Low; } - const UShort& PRDT::High() - { - return m_High; - } +const UShort& PRDT::High() { return m_High; } - const UIntPtr& PRDT::PhysicalAddress() - { - return m_PrdtAddr; - } +const UIntPtr& PRDT::PhysicalAddress() { return m_PrdtAddr; } - PRDT& PRDT::operator=(const UIntPtr& prdtAddress) - { - m_PrdtAddr = prdtAddress; - return *this; - } -} // namespace hCore +PRDT& PRDT::operator=(const UIntPtr& prdtAddress) { + m_PrdtAddr = prdtAddress; + return *this; +} +} // namespace hCore diff --git a/Private/Source/PageAllocator.cxx b/Private/Source/PageAllocator.cxx index e29710dd..59ad6b28 100644 --- a/Private/Source/PageAllocator.cxx +++ b/Private/Source/PageAllocator.cxx @@ -12,45 +12,39 @@ #include <NewKit/PageAllocator.hpp> // empty for now. -namespace hCore::Detail -{ - UIntPtr create_page_wrapper(Boolean rw, Boolean user) - { - auto addr = HAL::hal_create_page(rw, user); - - if (addr == kBadAddress) - { - kcout << "[create_page_wrapper] kBadAddress returned\n"; - panic(RUNTIME_CHECK_POINTER); - } - - return addr; - } - - void exec_disable(UIntPtr VirtualAddr) - { - PTE *VirtualAddrTable = reinterpret_cast<PTE*>(VirtualAddr); - MUST_PASS(!VirtualAddrTable->Accessed); - VirtualAddrTable->ExecDisable = true; - - flush_tlb(VirtualAddr); - } - - bool page_disable(UIntPtr VirtualAddr) - { - if (VirtualAddr) { - auto VirtualAddrTable = (PTE * )(VirtualAddr); - MUST_PASS(!VirtualAddrTable->Accessed); - - if (VirtualAddrTable->Accessed) - return false; - VirtualAddrTable->Present = false; - - flush_tlb(VirtualAddr); - - return true; - } - - return false; - } -} // namespace hCore::Detail +namespace hCore::Detail { +UIntPtr create_page_wrapper(Boolean rw, Boolean user) { + auto addr = HAL::hal_create_page(rw, user); + + if (addr == kBadAddress) { + kcout << "[create_page_wrapper] kBadAddress returned\n"; + panic(RUNTIME_CHECK_POINTER); + } + + return addr; +} + +void exec_disable(UIntPtr VirtualAddr) { + PTE *VirtualAddrTable = reinterpret_cast<PTE *>(VirtualAddr); + MUST_PASS(!VirtualAddrTable->Accessed); + VirtualAddrTable->ExecDisable = true; + + flush_tlb(VirtualAddr); +} + +bool page_disable(UIntPtr VirtualAddr) { + if (VirtualAddr) { + auto VirtualAddrTable = (PTE *)(VirtualAddr); + MUST_PASS(!VirtualAddrTable->Accessed); + + if (VirtualAddrTable->Accessed) return false; + VirtualAddrTable->Present = false; + + flush_tlb(VirtualAddr); + + return true; + } + + return false; +} +} // namespace hCore::Detail diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx index fc6b8e80..32c1f22a 100644 --- a/Private/Source/PageManager.cxx +++ b/Private/Source/PageManager.cxx @@ -10,137 +10,114 @@ #include <KernelKit/DebugOutput.hpp> #include <NewKit/PageManager.hpp> -namespace hCore -{ - PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable, UIntPtr VirtAddr) - : m_Rw(Rw), - m_User(User), - m_ExecDisable(ExecDisable), - m_VirtAddr(VirtAddr), - m_Cache(false), - m_Shareable(false), - m_Wt(false), - m_Present(true), - m_Accessed(false) - { - // special case for the null region. - if (VirtAddr == 0) - { - m_Wt = false; - m_Rw = false; - m_Cache = false; - m_Shareable = false; - } - } - - PTEWrapper::~PTEWrapper() - { - PTE* raw = reinterpret_cast<PTE*>(m_VirtAddr); - - MUST_PASS(raw); - MUST_PASS(!raw->Accessed); - - if (raw->Present) - raw->Present = false; - } - - void PTEWrapper::FlushTLB(Ref<PageManager> &pm) - { - pm.Leak().FlushTLB(this->m_VirtAddr); - } - - void PageManager::FlushTLB(UIntPtr VirtAddr) - { - if (VirtAddr == kBadAddress) - return; - - flush_tlb(VirtAddr); - } - - bool PTEWrapper::Reclaim() - { - if (!this->m_Present) - { - this->m_Present = true; - return true; - } - - return false; - } - - PTEWrapper *PageManager::Request(Boolean Rw, Boolean User, Boolean ExecDisable) - { - PTEWrapper *PageTableEntry = - reinterpret_cast<PTEWrapper*>(hCore::HAL::hal_alloc_page(sizeof(PTEWrapper), Rw, User)); - - if (PageTableEntry == nullptr) { - kcout << "PTEWrapper : Page table is nullptr!, kernel_new_ptr failed!"; - return nullptr; - } - - *PageTableEntry = PTEWrapper{Rw, User, ExecDisable, Detail::create_page_wrapper(Rw, User)}; - return PageTableEntry; - } - - bool PageManager::Free(Ref<PTEWrapper*> &wrapper) - { - if (wrapper) { - if (!Detail::page_disable(wrapper->VirtualAddress())) - return false; - - this->FlushTLB(wrapper->VirtualAddress()); - return true; - } - - return false; - } - - const UIntPtr &PTEWrapper::VirtualAddress() - { - return m_VirtAddr; - } - - bool PTEWrapper::Shareable() - { - auto raw = reinterpret_cast<PTE*>(m_VirtAddr); - - if (raw->Present) - { - m_Shareable = raw->Shared; - return m_Shareable; - } - else - { - kcout << "[PTEWrapper::Shareable] page is not present!"; - return false; - } - } - - bool PTEWrapper::Present() - { - auto raw = reinterpret_cast<PTE*>(m_VirtAddr); - - if (raw->Present) - { - m_Present = raw->Present; - return m_Present; - } - else - { - kcout << "[PTEWrapper::Present] page is not present!"; - return false; - } - } - - bool PTEWrapper::Access() - { - auto raw = reinterpret_cast<PTE*>(m_VirtAddr); - - if (raw->Present) - { - m_Accessed = raw->Accessed; - } - - return m_Accessed; - } -} // namespace hCore +namespace hCore { +PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable, + UIntPtr VirtAddr) + : m_Rw(Rw), + m_User(User), + m_ExecDisable(ExecDisable), + m_VirtAddr(VirtAddr), + m_Cache(false), + m_Shareable(false), + m_Wt(false), + m_Present(true), + m_Accessed(false) { + // special case for the null region. + if (VirtAddr == 0) { + m_Wt = false; + m_Rw = false; + m_Cache = false; + m_Shareable = false; + } +} + +PTEWrapper::~PTEWrapper() { + PTE *raw = reinterpret_cast<PTE *>(m_VirtAddr); + + MUST_PASS(raw); + MUST_PASS(!raw->Accessed); + + if (raw->Present) raw->Present = false; +} + +void PTEWrapper::FlushTLB(Ref<PageManager> &pm) { + pm.Leak().FlushTLB(this->m_VirtAddr); +} + +void PageManager::FlushTLB(UIntPtr VirtAddr) { + if (VirtAddr == kBadAddress) return; + + flush_tlb(VirtAddr); +} + +bool PTEWrapper::Reclaim() { + if (!this->m_Present) { + this->m_Present = true; + return true; + } + + return false; +} + +PTEWrapper *PageManager::Request(Boolean Rw, Boolean User, + Boolean ExecDisable) { + PTEWrapper *PageTableEntry = reinterpret_cast<PTEWrapper *>( + hCore::HAL::hal_alloc_page(sizeof(PTEWrapper), Rw, User)); + + if (PageTableEntry == nullptr) { + kcout << "PTEWrapper : Page table is nullptr!, kernel_new_ptr failed!"; + return nullptr; + } + + *PageTableEntry = + PTEWrapper{Rw, User, ExecDisable, Detail::create_page_wrapper(Rw, User)}; + return PageTableEntry; +} + +bool PageManager::Free(Ref<PTEWrapper *> &wrapper) { + if (wrapper) { + if (!Detail::page_disable(wrapper->VirtualAddress())) return false; + + this->FlushTLB(wrapper->VirtualAddress()); + return true; + } + + return false; +} + +const UIntPtr &PTEWrapper::VirtualAddress() { return m_VirtAddr; } + +bool PTEWrapper::Shareable() { + auto raw = reinterpret_cast<PTE *>(m_VirtAddr); + + if (raw->Present) { + m_Shareable = raw->Shared; + return m_Shareable; + } else { + kcout << "[PTEWrapper::Shareable] page is not present!"; + return false; + } +} + +bool PTEWrapper::Present() { + auto raw = reinterpret_cast<PTE *>(m_VirtAddr); + + if (raw->Present) { + m_Present = raw->Present; + return m_Present; + } else { + kcout << "[PTEWrapper::Present] page is not present!"; + return false; + } +} + +bool PTEWrapper::Access() { + auto raw = reinterpret_cast<PTE *>(m_VirtAddr); + + if (raw->Present) { + m_Accessed = raw->Accessed; + } + + return m_Accessed; +} +} // namespace hCore diff --git a/Private/Source/Panic.cxx b/Private/Source/Panic.cxx index 46e184d3..9e3dddfb 100644 --- a/Private/Source/Panic.cxx +++ b/Private/Source/Panic.cxx @@ -7,50 +7,43 @@ * ======================================================== */ -#include <NewKit/Panic.hpp> #include <ArchKit/Arch.hpp> -#include <NewKit/String.hpp> - #include <KernelKit/DebugOutput.hpp> +#include <NewKit/Panic.hpp> +#include <NewKit/String.hpp> -extern "C" [[noreturn]] void wait_for_debugger() -{ - while (true) - { - hCore::HAL::rt_cli(); - hCore::HAL::rt_halt(); - } +extern "C" [[noreturn]] void wait_for_debugger() { + while (true) { + hCore::HAL::rt_cli(); + hCore::HAL::rt_halt(); + } } /* Each error code is attributed with an ID, which will prompt a string onto the * screen. Wait for debugger... */ -namespace hCore -{ - void panic(const hCore::Int& id) - { +namespace hCore { +void panic(const hCore::Int &id) { #ifdef __DEBUG__ - kcout << "hCore: Kernel Panic! \r\n"; - kcout << StringBuilder::FromInt("kError : %\n", id); + kcout << "hCore: Kernel Panic! \r\n"; + kcout << StringBuilder::FromInt("kError : %\n", id); - DumpManager::Dump(); -#endif // __DEBUG__ + DumpManager::Dump(); +#endif // __DEBUG__ - wait_for_debugger(); - } + wait_for_debugger(); +} - void runtime_check(bool expr, const char *file, const char *line) - { - if (!expr) - { +void runtime_check(bool expr, const char *file, const char *line) { + if (!expr) { #ifdef __DEBUG__ - kcout << "[KERNEL] Check Failed!\n"; - kcout << "[KERNEL] File: " << file << "\n"; - kcout << "[KERNEL] Where: " << line << "\n"; + kcout << "[KERNEL] Check Failed!\n"; + kcout << "[KERNEL] File: " << file << "\n"; + kcout << "[KERNEL] Where: " << line << "\n"; -#endif // __DEBUG__ +#endif // __DEBUG__ - hCore::panic(RUNTIME_CHECK_FAILED); // Runtime Check failed - } - } -} // namespace hCore + hCore::panic(RUNTIME_CHECK_FAILED); // Runtime Check failed + } +} +} // namespace hCore diff --git a/Private/Source/PermissionSelector.cxx b/Private/Source/PermissionSelector.cxx index 04245502..69bb949b 100644 --- a/Private/Source/PermissionSelector.cxx +++ b/Private/Source/PermissionSelector.cxx @@ -13,31 +13,24 @@ #include <KernelKit/PermissionSelector.hxx> #include <NewKit/Panic.hpp> -namespace hCore -{ -PermissionSelector::PermissionSelector(const Int32 &sel) : fRing((RingKind)sel) -{ - MUST_PASS(sel > 0); +namespace hCore { +PermissionSelector::PermissionSelector(const Int32 &sel) + : fRing((RingKind)sel) { + MUST_PASS(sel > 0); } -PermissionSelector::PermissionSelector(const RingKind &ringKind) : fRing(ringKind) -{ -} +PermissionSelector::PermissionSelector(const RingKind &ringKind) + : fRing(ringKind) {} PermissionSelector::~PermissionSelector() = default; -bool PermissionSelector::operator==(const PermissionSelector &lhs) -{ - return lhs.fRing == this->fRing; +bool PermissionSelector::operator==(const PermissionSelector &lhs) { + return lhs.fRing == this->fRing; } -bool PermissionSelector::operator!=(const PermissionSelector &lhs) -{ - return lhs.fRing != this->fRing; +bool PermissionSelector::operator!=(const PermissionSelector &lhs) { + return lhs.fRing != this->fRing; } -const RingKind &PermissionSelector::Ring() noexcept -{ - return this->fRing; -} -} // namespace hCore +const RingKind &PermissionSelector::Ring() noexcept { return this->fRing; } +} // namespace hCore diff --git a/Private/Source/Pmm.cxx b/Private/Source/Pmm.cxx index 5d4ce965..b87e450b 100644 --- a/Private/Source/Pmm.cxx +++ b/Private/Source/Pmm.cxx @@ -10,84 +10,69 @@ #include <KernelKit/DebugOutput.hpp> #include <NewKit/Pmm.hpp> -namespace hCore -{ - Pmm::Pmm() = default; +namespace hCore { +Pmm::Pmm() = default; - Pmm::Pmm(Ref<PageManager*> &pm) : m_PageManager(pm) - { - MUST_PASS(pm.Leak()); - kcout << "[PMM] New PhysicalMemoryManager\r\n"; - } +Pmm::Pmm(Ref<PageManager *> &pm) : m_PageManager(pm) { + MUST_PASS(pm.Leak()); + kcout << "[PMM] New PhysicalMemoryManager\r\n"; +} - Pmm::~Pmm() = default; +Pmm::~Pmm() = default; - /* If this returns Null pointer, enter emergency mode */ - Ref<PTEWrapper*> Pmm::RequestPage(Boolean user, Boolean readWrite) - { - if (m_PageManager) - { - PTEWrapper *pt = m_PageManager.Leak()->Request(user, readWrite, true); +/* If this returns Null pointer, enter emergency mode */ +Ref<PTEWrapper *> Pmm::RequestPage(Boolean user, Boolean readWrite) { + if (m_PageManager) { + PTEWrapper *pt = m_PageManager.Leak()->Request(user, readWrite, true); - if (pt) - return Ref<PTEWrapper*>(pt); + if (pt) return Ref<PTEWrapper *>(pt); - return {}; - } + return {}; + } - kcout << "[Pmm::RequestPage] Ref<PTEWrapper*> could not be created! " - "m_PageManager is nullptr!\r\n"; + kcout << "[Pmm::RequestPage] Ref<PTEWrapper*> could not be created! " + "m_PageManager is nullptr!\r\n"; - return {}; - } + return {}; +} - Boolean Pmm::FreePage(Ref<PTEWrapper*> PageRef) - { - if (!PageRef) - return false; +Boolean Pmm::FreePage(Ref<PTEWrapper *> PageRef) { + if (!PageRef) return false; - PageRef->m_Present = false; + PageRef->m_Present = false; - return true; - } + return true; +} - Boolean Pmm::TogglePresent(Ref<PTEWrapper*> PageRef, Boolean Enable) - { - if (!PageRef) - return false; +Boolean Pmm::TogglePresent(Ref<PTEWrapper *> PageRef, Boolean Enable) { + if (!PageRef) return false; - PageRef->m_Present = Enable; + PageRef->m_Present = Enable; - return true; - } + return true; +} - Boolean Pmm::ToggleUser(Ref<PTEWrapper*> PageRef, Boolean Enable) - { - if (!PageRef) - return false; +Boolean Pmm::ToggleUser(Ref<PTEWrapper *> PageRef, Boolean Enable) { + if (!PageRef) return false; - PageRef->m_Rw = Enable; + PageRef->m_Rw = Enable; - return true; - } + return true; +} - Boolean Pmm::ToggleRw(Ref<PTEWrapper*> PageRef, Boolean Enable) - { - if (!PageRef) - return false; +Boolean Pmm::ToggleRw(Ref<PTEWrapper *> PageRef, Boolean Enable) { + if (!PageRef) return false; - PageRef->m_Rw = Enable; + PageRef->m_Rw = Enable; - return true; - } + return true; +} - Boolean Pmm::ToggleShare(Ref<PTEWrapper*> PageRef, Boolean Enable) - { - if (!PageRef) - return false; +Boolean Pmm::ToggleShare(Ref<PTEWrapper *> PageRef, Boolean Enable) { + if (!PageRef) return false; - PageRef->m_Shareable = Enable; + PageRef->m_Shareable = Enable; - return true; - } -} // namespace hCore + return true; +} +} // namespace hCore diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx index 664a1c7c..987b8093 100644 --- a/Private/Source/ProcessManager.cxx +++ b/Private/Source/ProcessManager.cxx @@ -10,7 +10,7 @@ #include "NewKit/Panic.hpp" #include <KernelKit/ProcessManager.hpp> #include <KernelKit/SMPManager.hpp> -#include <NewKit/KHeap.hpp> +#include <NewKit/KernelHeap.hpp> #include <NewKit/String.hpp> #define kPoolAlign (4) diff --git a/Private/Source/Property.cxx b/Private/Source/Property.cxx index ebb87fb9..f3633598 100644 --- a/Private/Source/Property.cxx +++ b/Private/Source/Property.cxx @@ -9,15 +9,10 @@ #include <CFKit/Property.hpp> -namespace hCore -{ - bool Property::StringEquals(StringView &name) - { - return m_sName && this->m_sName == name; - } +namespace hCore { +bool Property::StringEquals(StringView& name) { + return m_sName && this->m_sName == name; +} - const PropertyId& Property::GetPropertyById() - { - return m_Action; - } -} // namespace hCore +const PropertyId& Property::GetPropertyById() { return m_Action; } +} // namespace hCore diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/RuntimeMain.cxx index 210a5c43..a2b777d8 100644 --- a/Private/Source/RuntimeMain.cxx +++ b/Private/Source/RuntimeMain.cxx @@ -7,7 +7,6 @@ * ======================================================== */ -#include "NewKit/Defines.hpp" #include <ArchKit/Arch.hpp> #include <KernelKit/CodeManager.hpp> #include <KernelKit/FileManager.hpp> @@ -17,20 +16,18 @@ extern "C" void (*__SYSTEM_FINI)(); extern "C" void (**__SYSTEM_INIT)(); -extern "C" void RuntimeMain() -{ - for (hCore::SizeT index_init = 0UL; __SYSTEM_INIT[index_init] != __SYSTEM_FINI; ++index_init) - { - __SYSTEM_INIT[index_init](); - } +extern "C" void RuntimeMain() { + for (hCore::SizeT index_init = 0UL; + __SYSTEM_INIT[index_init] != __SYSTEM_FINI; ++index_init) { + __SYSTEM_INIT[index_init](); + } - MUST_PASS(hCore::init_hal()); + MUST_PASS(hCore::init_hal()); - hCore::IFilesystemManager::Mount(new hCore::NewFilesystemManager()); - hCore::PEFLoader img("/System/Seeker.cm"); + hCore::IFilesystemManager::Mount(new hCore::NewFilesystemManager()); + hCore::PEFLoader img("/System/Seeker.cm"); - if (!hCore::Utils::execute_from_image(img)) - { - hCore::panic(RUNTIME_CHECK_BOOTSTRAP); - } + if (!hCore::Utils::execute_from_image(img)) { + hCore::panic(RUNTIME_CHECK_BOOTSTRAP); + } } diff --git a/Private/Source/SMPManager.cxx b/Private/Source/SMPManager.cxx index 4897165b..05e47ea8 100644 --- a/Private/Source/SMPManager.cxx +++ b/Private/Source/SMPManager.cxx @@ -7,144 +7,137 @@ * ======================================================== */ -#include <KernelKit/SMPManager.hpp> -#include <KernelKit/ProcessManager.hpp> #include <ArchKit/Arch.hpp> +#include <KernelKit/ProcessManager.hpp> +#include <KernelKit/SMPManager.hpp> /// BUGS: 0 //! This file handles multi processing in hCore. //! Multi processing is needed for File I/O, networking and scheduling. -namespace hCore -{ - // A ProcessorCore class takes care of it's owned hardware thread. - // It has a stack for it's core. +namespace hCore { +// A ProcessorCore class takes care of it's owned hardware thread. +// It has a stack for it's core. + +// @brief constructor +ProcessorCore::ProcessorCore() = default; + +// @brief destructor +ProcessorCore::~ProcessorCore() = default; + +//! @brief returns the id - // @brief constructor - ProcessorCore::ProcessorCore() = default; +const ThreadID& ProcessorCore::ID() noexcept { return m_ID; } - // @brief destructor - ProcessorCore::~ProcessorCore() = default; - - //! @brief returns the id +//! @brief returns the kind - const ThreadID& ProcessorCore::ID() noexcept { return m_ID; } - - //! @brief returns the kind +const ThreadKind& ProcessorCore::Kind() noexcept { return m_Kind; } - const ThreadKind& ProcessorCore::Kind() noexcept { return m_Kind; } +//! @brief is the core busy? - //! @brief is the core busy? +bool ProcessorCore::IsBusy() noexcept { return m_Busy; } - bool ProcessorCore::IsBusy() noexcept { return m_Busy; } +/// @brief Get processor stack frame. - /// @brief Get processor stack frame. +HAL::StackFrame* ProcessorCore::StackFrame() noexcept { + MUST_PASS(m_Stack); + return m_Stack; +} - HAL::StackFrame* ProcessorCore::StackFrame() noexcept - { - MUST_PASS(m_Stack); - return m_Stack; - } +void ProcessorCore::Busy(const bool busy) noexcept { m_Busy = busy; } - void ProcessorCore::Busy(const bool busy) noexcept { m_Busy = busy; } +ProcessorCore::operator bool() { return m_Stack; } - ProcessorCore::operator bool() { return m_Stack; } +/// @brief Wakeup the processor. - /// @brief Wakeup the processor. +void ProcessorCore::Wake(const bool wakeup) noexcept { + m_Wakeup = wakeup; - void ProcessorCore::Wake(const bool wakeup) noexcept - { - m_Wakeup = wakeup; + if (!m_Wakeup) + rt_hang_thread(m_Stack); + else + rt_wakeup_thread(m_Stack); +} - if (!m_Wakeup) - rt_hang_thread(m_Stack); - else - rt_wakeup_thread(m_Stack); - } +bool ProcessorCore::Switch(HAL::StackFrame* stack) { + if (stack == nullptr) return false; - bool ProcessorCore::Switch(HAL::StackFrame* stack) - { - if (stack == nullptr) - return false; + return rt_do_context_switch(m_Stack, stack) == 0; +} - return rt_do_context_switch(m_Stack, stack) == 0; - } +///! @brief Tells if processor is waked up. +bool ProcessorCore::IsWakeup() noexcept { return m_Wakeup; } - ///! @brief Tells if processor is waked up. - bool ProcessorCore::IsWakeup() noexcept { return m_Wakeup; } +//! @brief Constructor and destructor - //! @brief Constructor and destructor +///! @brief Default constructor. +SMPManager::SMPManager() = default; - ///! @brief Default constructor. - SMPManager::SMPManager() = default; +///! @brief Default destructor. +SMPManager::~SMPManager() = default; - ///! @brief Default destructor. - SMPManager::~SMPManager() = default; +/// @brief Shared singleton function +Ref<SMPManager> SMPManager::Shared() { + static SMPManager manager; + return {manager}; +} - /// @brief Shared singleton function - Ref<SMPManager> SMPManager::Shared() - { - static SMPManager manager; - return { manager }; - } +/// @brief Get Stack Frame of Core +HAL::StackFramePtr SMPManager::GetStackFrame() noexcept { + if (m_ThreadList[m_CurrentThread].Leak() && + ProcessHelper::GetCurrentPID() == + m_ThreadList[m_CurrentThread].Leak().Leak().m_PID) + return m_ThreadList[m_CurrentThread].Leak().Leak().m_Stack; - /// @brief Get Stack Frame of Core - HAL::StackFramePtr SMPManager::GetStackFrame() noexcept - { - if (m_ThreadList[m_CurrentThread].Leak() && - ProcessHelper::GetCurrentPID() == m_ThreadList[m_CurrentThread].Leak().Leak().m_PID) - return m_ThreadList[m_CurrentThread].Leak().Leak().m_Stack; + return nullptr; +} - return nullptr; - } +/// @brief Finds and switch to a free core. +bool SMPManager::Switch(HAL::StackFrame* stack) { + if (stack == nullptr) return false; - /// @brief Finds and switch to a free core. - bool SMPManager::Switch(HAL::StackFrame* stack) - { - if (stack == nullptr) - return false; + for (SizeT idx = 0; idx < kMaxHarts; ++idx) { + // stack != nullptr -> if core is used, then continue. + if (!m_ThreadList[idx].Leak() || + !m_ThreadList[idx].Leak().Leak().IsWakeup() || + m_ThreadList[idx].Leak().Leak().IsBusy()) + continue; - for (SizeT idx = 0; idx < kMaxHarts; ++idx) - { - // stack != nullptr -> if core is used, then continue. - if (!m_ThreadList[idx].Leak() || - !m_ThreadList[idx].Leak().Leak().IsWakeup() || - m_ThreadList[idx].Leak().Leak().IsBusy()) - continue; + m_ThreadList[idx].Leak().Leak().m_ID = idx; + m_ThreadList[idx].Leak().Leak().m_Stack = stack; + m_ThreadList[idx].Leak().Leak().m_PID = ProcessHelper::GetCurrentPID(); - m_ThreadList[idx].Leak().Leak().m_ID = idx; - m_ThreadList[idx].Leak().Leak().m_Stack = stack; - m_ThreadList[idx].Leak().Leak().m_PID = ProcessHelper::GetCurrentPID(); - - m_ThreadList[idx].Leak().Leak().Busy(true); + m_ThreadList[idx].Leak().Leak().Busy(true); - Boolean ret = (rt_do_context_switch(rt_get_current_context(), stack) == 0); - - m_ThreadList[idx].Leak().Leak().Busy(false); + Boolean ret = (rt_do_context_switch(rt_get_current_context(), stack) == 0); - return ret; - } + m_ThreadList[idx].Leak().Leak().Busy(false); - return false; - } + return ret; + } - /** - * Index hart - * @param idx - * @return - */ - Ref<ProcessorCore> SMPManager::operator[](const SizeT& idx) { return m_ThreadList[idx].Leak(); } - - /** - * Check if thread pool isn't empty. - * @return - */ - SMPManager::operator bool() noexcept { return !m_ThreadList.Empty(); } - - /** - * Reverse operator bool - * @return - */ - bool SMPManager::operator!() noexcept { return m_ThreadList.Empty(); } -} // namespace hCore + return false; +} + +/** + * Index hart + * @param idx + * @return + */ +Ref<ProcessorCore> SMPManager::operator[](const SizeT& idx) { + return m_ThreadList[idx].Leak(); +} + +/** + * Check if thread pool isn't empty. + * @return + */ +SMPManager::operator bool() noexcept { return !m_ThreadList.Empty(); } + +/** + * Reverse operator bool + * @return + */ +bool SMPManager::operator!() noexcept { return m_ThreadList.Empty(); } +} // namespace hCore diff --git a/Private/Source/Semaphore.cxx b/Private/Source/Semaphore.cxx index 0c530274..5702b9fb 100644 --- a/Private/Source/Semaphore.cxx +++ b/Private/Source/Semaphore.cxx @@ -7,47 +7,38 @@ * ======================================================== */ +#include <KernelKit/ProcessManager.hpp> #include <KernelKit/Semaphore.hpp> - #include <KernelKit/Timer.hpp> -#include <KernelKit/ProcessManager.hpp> -namespace hCore -{ - bool Semaphore::Unlock() noexcept - { - if (fLockingProcess) - fLockingProcess = nullptr; +namespace hCore { +bool Semaphore::Unlock() noexcept { + if (fLockingProcess) fLockingProcess = nullptr; - return fLockingProcess == nullptr; - } + return fLockingProcess == nullptr; +} - bool Semaphore::Lock(Process* process) - { - if (!process || - fLockingProcess) - return false; +bool Semaphore::Lock(Process* process) { + if (!process || fLockingProcess) return false; - fLockingProcess = process; + fLockingProcess = process; - return true; - } + return true; +} - bool Semaphore::IsLocked() const { return fLockingProcess; } +bool Semaphore::IsLocked() const { return fLockingProcess; } - bool Semaphore::LockOrWait(Process* process, const Int64& seconds) - { - if (process == nullptr) - return false; +bool Semaphore::LockOrWait(Process* process, const Int64& seconds) { + if (process == nullptr) return false; - HardwareTimer timer(Seconds(seconds)); - timer.Wait(); + HardwareTimer timer(Seconds(seconds)); + timer.Wait(); - return this->Lock(process); - } + return this->Lock(process); +} - void Semaphore::Sync() noexcept - { - while (fLockingProcess) {} - } +void Semaphore::Sync() noexcept { + while (fLockingProcess) { + } } +} // namespace hCore diff --git a/Private/Source/SharedObject.cxx b/Private/Source/SharedObject.cxx index a6ccc224..0e824b27 100644 --- a/Private/Source/SharedObject.cxx +++ b/Private/Source/SharedObject.cxx @@ -18,38 +18,37 @@ using namespace hCore; /***********************************************************************************/ -extern "C" SharedObject *__LibMain(VoidPtr image) -{ - /***********************************************************************************/ - /* Allocate new library to be added to the lookup table. */ - /***********************************************************************************/ +extern "C" SharedObject *__LibMain(VoidPtr image) { + /***********************************************************************************/ + /* Allocate new library to be added to the lookup table. + */ + /***********************************************************************************/ - SharedObject *library = hcore_tls_new_class<SharedObject>(); + SharedObject *library = hcore_tls_new_class<SharedObject>(); - if (!library) - { - kcout << "__LibMain: Out of Memory!\n"; - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + if (!library) { + kcout << "__LibMain: Out of Memory!\n"; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); - return nullptr; - } + return nullptr; + } - library->Mount(hcore_tls_new_class<SharedObject::SharedObjectTraits>()); + library->Mount(hcore_tls_new_class<SharedObject::SharedObjectTraits>()); - if (!library->Get()) - { - kcout << "__LibMain: Out of Memory!\n"; - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + if (!library->Get()) { + kcout << "__LibMain: Out of Memory!\n"; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); - return nullptr; - } + return nullptr; + } - library->Get()->fImageObject = ProcessManager::Shared().Leak().GetCurrent().Leak().Image; - library->Get()->fImageEntrypointOffset = library->Load<VoidPtr>(kPefStart); + library->Get()->fImageObject = + ProcessManager::Shared().Leak().GetCurrent().Leak().Image; + library->Get()->fImageEntrypointOffset = library->Load<VoidPtr>(kPefStart); - kcout << "__LibMain: Done allocating Shared Library...\n"; + kcout << "__LibMain: Done allocating Shared Library...\n"; - return library; + return library; } /***********************************************************************************/ diff --git a/Private/Source/Storage/ATA.cxx b/Private/Source/Storage/ATA.cxx index 08fa43b3..f960907b 100644 --- a/Private/Source/Storage/ATA.cxx +++ b/Private/Source/Storage/ATA.cxx @@ -7,93 +7,85 @@ * ======================================================== */ -#include <StorageKit/ATA.hpp> #include <ArchKit/Arch.hpp> +#include <StorageKit/ATA.hpp> //! @brief Driver for ATA, listens to a specific address for data to come. //! mapped by NewFirmware. #define kATAError 2 -namespace hCore -{ - Ref<PRDT*> kPrdt = nullptr; +namespace hCore { +Ref<PRDT*> kPrdt = nullptr; - bool set_prdt_struct(Ref<PRDT*>& refCtrl) - { - if (!kPrdt) - { - kPrdt = refCtrl; - kcout << "[set_prdt_struct] PRDT is set."; +bool set_prdt_struct(Ref<PRDT*>& refCtrl) { + if (!kPrdt) { + kPrdt = refCtrl; + kcout << "[set_prdt_struct] PRDT is set."; - return true; - } + return true; + } - kcout << "[set_prdt_struct] [WARNING] Tried to change PRDT.\n"; - return false; - } + kcout << "[set_prdt_struct] [WARNING] Tried to change PRDT.\n"; + return false; +} - enum - { - k28BitRead = 0xC8, - k48BitRead = 0x25, - k28BitWrite = 0xCA, - k48BitWrite = 0x35, - }; +enum { + k28BitRead = 0xC8, + k48BitRead = 0x25, + k28BitWrite = 0xCA, + k48BitWrite = 0x35, +}; - const char* ata_read_28(ULong lba) - { - static char buffer[512]; +const char* ata_read_28(ULong lba) { + static char buffer[512]; - UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); + UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); - packet[0] = k28BitRead; - packet[1] = (UIntPtr)&buffer; - packet[2] = lba; + packet[0] = k28BitRead; + packet[1] = (UIntPtr)&buffer; + packet[2] = lba; - rt_wait_for_io(); + rt_wait_for_io(); - return buffer; - } + return buffer; +} - const char* ata_read_48(ULong lba) - { - static char buffer[512]; +const char* ata_read_48(ULong lba) { + static char buffer[512]; - UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); + UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); - packet[0] = k48BitRead; - packet[1] = (UIntPtr)&buffer; - packet[4] = lba; + packet[0] = k48BitRead; + packet[1] = (UIntPtr)&buffer; + packet[4] = lba; - rt_wait_for_io(); + rt_wait_for_io(); - return buffer; - } + return buffer; +} - Int32 ata_write_48(ULong lba, const char *text) - { - UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); +Int32 ata_write_48(ULong lba, const char* text) { + UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); - packet[0] = k48BitWrite; - packet[1] = (UIntPtr)&text; - packet[2] = lba; + packet[0] = k48BitWrite; + packet[1] = (UIntPtr)&text; + packet[2] = lba; - rt_wait_for_io(); + rt_wait_for_io(); - return packet[1] == 2 ? kATAError : 0; - } + return packet[1] == 2 ? kATAError : 0; +} - Int32 ata_write_28(ULong lba, const char *text) - { - UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); +Int32 ata_write_28(ULong lba, const char* text) { + UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); - packet[0] = k28BitWrite; - packet[1] = (UIntPtr)&text; - packet[2] = lba; + packet[0] = k28BitWrite; + packet[1] = (UIntPtr)&text; + packet[2] = lba; - rt_wait_for_io(); + rt_wait_for_io(); - return packet[1] == 2 ? kATAError : 0; - } -} // namespace hCore + return packet[1] == 2 ? kATAError : 0; +} +} // namespace hCore diff --git a/Private/Source/Storage/NVME.cxx b/Private/Source/Storage/NVME.cxx index aa1d8ecc..9501b8fa 100644 --- a/Private/Source/Storage/NVME.cxx +++ b/Private/Source/Storage/NVME.cxx @@ -9,10 +9,6 @@ #include <StorageKit/NVME.hpp> -namespace hCore -{ - const char *NVMEDevice::Name() const - { - return ("NVMEDevice"); - } -} // namespace hCore +namespace hCore { +const char *NVMEDevice::Name() const { return ("NVMEDevice"); } +} // namespace hCore diff --git a/Private/Source/Storage/Storage.cxx b/Private/Source/Storage/Storage.cxx index 6384479a..2340763a 100644 --- a/Private/Source/Storage/Storage.cxx +++ b/Private/Source/Storage/Storage.cxx @@ -9,4 +9,5 @@ #include <StorageKit/Storage.hpp> -const OSScsiPacket kCDRomPacketTemplate = { 0x43, 0, 1, 0, 0, 0, 0, 12, 0x40, 0, 0 }; +const OSScsiPacket kCDRomPacketTemplate = {0x43, 0, 1, 0, 0, 0, + 0, 12, 0x40, 0, 0}; diff --git a/Private/Source/String.cxx b/Private/Source/String.cxx index 3ad2a0cd..b4f95f6c 100644 --- a/Private/Source/String.cxx +++ b/Private/Source/String.cxx @@ -10,230 +10,185 @@ #include <NewKit/String.hpp> #include <NewKit/Utils.hpp> -namespace hCore -{ - Char* StringView::Data() { return m_Data; } +namespace hCore { +Char *StringView::Data() { return m_Data; } - const Char* StringView::CData() { return m_Data; } +const Char *StringView::CData() { return m_Data; } - Size StringView::Length() const { return string_length(m_Data); } +Size StringView::Length() const { return string_length(m_Data); } - bool StringView::operator==(const StringView &rhs) const - { - if (rhs.Length() != this->Length()) - return false; +bool StringView::operator==(const StringView &rhs) const { + if (rhs.Length() != this->Length()) return false; - for (Size index = 0; index < this->Length(); ++index) - { - if (rhs.m_Data[index] != m_Data[index]) - return false; - } + for (Size index = 0; index < this->Length(); ++index) { + if (rhs.m_Data[index] != m_Data[index]) return false; + } - return true; - } + return true; +} - bool StringView::operator==(const Char *rhs) const - { - if (string_length(rhs) != this->Length()) - return false; +bool StringView::operator==(const Char *rhs) const { + if (string_length(rhs) != this->Length()) return false; - for (Size index = 0; index < string_length(rhs); ++index) - { - if (rhs[index] != m_Data[index]) - return false; - } + for (Size index = 0; index < string_length(rhs); ++index) { + if (rhs[index] != m_Data[index]) return false; + } - return true; - } + return true; +} - bool StringView::operator!=(const StringView &rhs) const - { - if (rhs.Length() != this->Length()) - return false; +bool StringView::operator!=(const StringView &rhs) const { + if (rhs.Length() != this->Length()) return false; - for (Size index = 0; index < rhs.Length(); ++index) - { - if (rhs.m_Data[index] == m_Data[index]) - return false; - } + for (Size index = 0; index < rhs.Length(); ++index) { + if (rhs.m_Data[index] == m_Data[index]) return false; + } - return true; - } + return true; +} - bool StringView::operator!=(const Char *rhs) const - { - if (string_length(rhs) != this->Length()) - return false; +bool StringView::operator!=(const Char *rhs) const { + if (string_length(rhs) != this->Length()) return false; - for (Size index = 0; index < string_length(rhs); ++index) - { - if (rhs[index] == m_Data[index]) - return false; - } - - return true; - } + for (Size index = 0; index < string_length(rhs); ++index) { + if (rhs[index] == m_Data[index]) return false; + } - ErrorOr<StringView> StringBuilder::Construct(const Char *data) - { - if (!data || - *data == 0) - return {}; + return true; +} - StringView view(string_length(data)); - - rt_copy_memory(reinterpret_cast<voidPtr>(const_cast<Char*>(data)), reinterpret_cast<voidPtr>(view.Data()), - view.Length()); +ErrorOr<StringView> StringBuilder::Construct(const Char *data) { + if (!data || *data == 0) return {}; - return ErrorOr<StringView>(view); - } + StringView view(string_length(data)); - const char* StringBuilder::FromInt(const char *fmt, int i) - { - if (!fmt) - return ("-1"); + rt_copy_memory(reinterpret_cast<voidPtr>(const_cast<Char *>(data)), + reinterpret_cast<voidPtr>(view.Data()), view.Length()); - char* ret = (char*)__alloca(sizeof(char) * 8 + string_length(fmt)); + return ErrorOr<StringView>(view); +} - if (!ret) - return ("-1"); +const char *StringBuilder::FromInt(const char *fmt, int i) { + if (!fmt) return ("-1"); - Char result[8]; + char *ret = (char *)__alloca(sizeof(char) * 8 + string_length(fmt)); - if (!to_str(result, sizeof(int), i)) - { - return ("-1"); - } + if (!ret) return ("-1"); - const auto fmt_len = string_length(fmt); - const auto res_len = string_length(result); + Char result[8]; - for (Size idx = 0; idx < fmt_len; ++idx) - { - if (fmt[idx] == '%') { - SizeT result_cnt = idx; + if (!to_str(result, sizeof(int), i)) { + return ("-1"); + } - for (auto y_idx = idx; y_idx < res_len; ++y_idx) { - ret[result_cnt] = result[y_idx]; - ++result_cnt; - } + const auto fmt_len = string_length(fmt); + const auto res_len = string_length(result); - break; - } + for (Size idx = 0; idx < fmt_len; ++idx) { + if (fmt[idx] == '%') { + SizeT result_cnt = idx; - ret[idx] = fmt[idx]; - } + for (auto y_idx = idx; y_idx < res_len; ++y_idx) { + ret[result_cnt] = result[y_idx]; + ++result_cnt; + } - return ret; /* Copy that ret into a buffer, Alloca allocates to the stack */ + break; } - const char *StringBuilder::FromBool(const char *fmt, bool i) - { - if (!fmt) - return ("?"); + ret[idx] = fmt[idx]; + } - const char* boolean_expr = i ? "true" : "false"; - char* ret = (char*)__alloca((sizeof(char) * i) ? 4 : 5 + string_length(fmt)); + return ret; /* Copy that ret into a buffer, Alloca allocates to the stack */ +} - if (!ret) - return ("?"); +const char *StringBuilder::FromBool(const char *fmt, bool i) { + if (!fmt) return ("?"); - const auto fmt_len = string_length(fmt); - const auto res_len = string_length(boolean_expr); + const char *boolean_expr = i ? "true" : "false"; + char *ret = (char *)__alloca((sizeof(char) * i) ? 4 : 5 + string_length(fmt)); - for (Size idx = 0; idx < fmt_len; ++idx) - { - if (fmt[idx] == '%') { - SizeT result_cnt = idx; + if (!ret) return ("?"); - for (auto y_idx = idx; y_idx < res_len; ++y_idx) - { - ret[result_cnt] = boolean_expr[y_idx]; - ++result_cnt; - } + const auto fmt_len = string_length(fmt); + const auto res_len = string_length(boolean_expr); - break; - } + for (Size idx = 0; idx < fmt_len; ++idx) { + if (fmt[idx] == '%') { + SizeT result_cnt = idx; - ret[idx] = fmt[idx]; - } + for (auto y_idx = idx; y_idx < res_len; ++y_idx) { + ret[result_cnt] = boolean_expr[y_idx]; + ++result_cnt; + } - return ret; + break; } - bool StringBuilder::Equals(const char *lhs, const char *rhs) - { - if (string_length(rhs) != string_length(lhs)) - return false; + ret[idx] = fmt[idx]; + } - for (Size index = 0; index < string_length(rhs); ++index) - { - if (rhs[index] != lhs[index]) - return false; - } + return ret; +} - return true; - } +bool StringBuilder::Equals(const char *lhs, const char *rhs) { + if (string_length(rhs) != string_length(lhs)) return false; - const char *StringBuilder::Format(const char *fmt, const char *fmt2) - { - if (!fmt || !fmt2) - return ("?"); - - char* ret = (char*)alloca(sizeof(char) * string_length(fmt2) + string_length(fmt2)); - - if (!ret) - return ("?"); - - for (Size idx = 0; idx < string_length(fmt); ++idx) - { - if (fmt[idx] == '%') { - Size result_cnt = idx; - for (Size y_idx = 0; y_idx < string_length(fmt2); ++y_idx) - { - ret[result_cnt] = fmt2[y_idx]; - ++result_cnt; - } - - break; - } - - ret[idx] = fmt[idx]; - } - - return ret; - } + for (Size index = 0; index < string_length(rhs); ++index) { + if (rhs[index] != lhs[index]) return false; + } - static void string_append(char *lhs, char *rhs, int cur) - { - if (lhs && rhs && - cur < string_length(lhs)) - { - SizeT sz_rhs = string_length(rhs); + return true; +} - rt_copy_memory(rhs, lhs + cur, sz_rhs); - } - } +const char *StringBuilder::Format(const char *fmt, const char *fmt2) { + if (!fmt || !fmt2) return ("?"); + + char *ret = + (char *)alloca(sizeof(char) * string_length(fmt2) + string_length(fmt2)); - StringView& StringView::operator+=(const Char *rhs) - { - if (string_length(rhs) > string_length(this->m_Data)) - return *this; + if (!ret) return ("?"); - string_append(this->m_Data, const_cast<char*>(rhs), this->m_Cur); - this->m_Cur += string_length(rhs); - - return *this; + for (Size idx = 0; idx < string_length(fmt); ++idx) { + if (fmt[idx] == '%') { + Size result_cnt = idx; + for (Size y_idx = 0; y_idx < string_length(fmt2); ++y_idx) { + ret[result_cnt] = fmt2[y_idx]; + ++result_cnt; + } + + break; } - StringView& StringView::operator+=(const StringView &rhs) - { - if (string_length(rhs.m_Data) > string_length(this->m_Data)) - return *this; + ret[idx] = fmt[idx]; + } - string_append(this->m_Data, const_cast<char*>(rhs.m_Data), this->m_Cur); - this->m_Cur += string_length(const_cast<char*>(rhs.m_Data)); + return ret; +} - return *this; - } -} // namespace hCore +static void string_append(char *lhs, char *rhs, int cur) { + if (lhs && rhs && cur < string_length(lhs)) { + SizeT sz_rhs = string_length(rhs); + + rt_copy_memory(rhs, lhs + cur, sz_rhs); + } +} + +StringView &StringView::operator+=(const Char *rhs) { + if (string_length(rhs) > string_length(this->m_Data)) return *this; + + string_append(this->m_Data, const_cast<char *>(rhs), this->m_Cur); + this->m_Cur += string_length(rhs); + + return *this; +} + +StringView &StringView::operator+=(const StringView &rhs) { + if (string_length(rhs.m_Data) > string_length(this->m_Data)) return *this; + + string_append(this->m_Data, const_cast<char *>(rhs.m_Data), this->m_Cur); + this->m_Cur += string_length(const_cast<char *>(rhs.m_Data)); + + return *this; +} +} // namespace hCore diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx index bcafdd10..66ec69d6 100644 --- a/Private/Source/ThreadLocalStorage.cxx +++ b/Private/Source/ThreadLocalStorage.cxx @@ -17,16 +17,15 @@ using namespace hCore; * @param ptr * @return if the cookie is enabled. */ -Boolean hcore_tls_check(VoidPtr ptr) -{ - if (!ptr) - return false; +Boolean hcore_tls_check(VoidPtr ptr) { + if (!ptr) return false; - const char* _ptr = (const char*)ptr; + const char* _ptr = (const char*)ptr; - kcout << "TLS: Check for cookie...\n"; + kcout << "TLS: Checking for cookie...\n"; - return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 && _ptr[2] == kCookieMag2; + return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 && + _ptr[2] == kCookieMag2; } /** @@ -34,11 +33,11 @@ Boolean hcore_tls_check(VoidPtr ptr) * @param ptr * @return */ -Void hcore_tls_check_syscall_impl(ThreadInformationBlock ptr) noexcept -{ - if (!hcore_tls_check(ptr.Cookie)) - { - kcout << "TLS: Verification failure, crashing...\n"; - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); - } +Void hcore_tls_check_syscall_impl(ThreadInformationBlock ptr) noexcept { + if (!hcore_tls_check(ptr.Cookie)) { + kcout << "TLS: Verification failure, crashing...\n"; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + } + + kcout << "TLS: Verification succeeded! Keeping on...\n"; } diff --git a/Private/Source/Timer.cxx b/Private/Source/Timer.cxx index 73343fad..137a5545 100644 --- a/Private/Source/Timer.cxx +++ b/Private/Source/Timer.cxx @@ -18,12 +18,11 @@ Int32 HardwareTimerInterface::Wait() noexcept { return H_UNIMPLEMENTED; } HardwareTimer::HardwareTimer(Int64 seconds) : fWaitFor(seconds) {} HardwareTimer::~HardwareTimer() { fWaitFor = 0; } -Int32 HardwareTimer::Wait() noexcept -{ - if (fWaitFor < 1) - return -1; +Int32 HardwareTimer::Wait() noexcept { + if (fWaitFor < 1) return -1; - while (*fDigitalTimer < (*fDigitalTimer + fWaitFor)) {} + while (*fDigitalTimer < (*fDigitalTimer + fWaitFor)) { + } - return 0; -}
\ No newline at end of file + return 0; +} diff --git a/Private/Source/URL.cxx b/Private/Source/URL.cxx index 0aa75ab9..02a3ec77 100644 --- a/Private/Source/URL.cxx +++ b/Private/Source/URL.cxx @@ -8,92 +8,80 @@ */ #include <CFKit/URL.hpp> -#include <NewKit/Utils.hpp> - #include <KernelKit/DebugOutput.hpp> +#include <NewKit/Utils.hpp> // Bugs = 0 -namespace hCore -{ - Url::Url(StringView &strUrl) : m_urlView(strUrl, false) {} - - Url::~Url() = default; - - constexpr const char *kProtos[] = { - "https", // http with the secure. - "http", // http without the secure - "file", // filesystem protocol - "ftp", // file transfer protocol - "params", // system settings - "rsh", // remote shell (gui) - }; - - constexpr const int kUrlOutSz = 3; //! :// - constexpr const int kProtosCount = 8; - constexpr const int kRangeSz = 4096; - - static ErrorOr<StringView> url_extract_location(const char *url) - { - if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz) - return ErrorOr<StringView>{-1}; - - StringView view(string_length(url)); - - SizeT i = 0; - bool scheme_found = false; - - for (; i < string_length(url); ++i) - { - if (!scheme_found) - { - for (int y = 0; kProtosCount; ++y) - { - if (string_in_string(view.CData(), kProtos[y])) - { - i += string_length(kProtos[y]) + kUrlOutSz; - scheme_found = true; - - break; - } - } - } - - view.Data()[i] = url[i]; - } +namespace hCore { +Url::Url(StringView &strUrl) : m_urlView(strUrl, false) {} - return ErrorOr<StringView>(view); - } +Url::~Url() = default; - static ErrorOr<StringView> url_extract_protocol(const char *url) - { - if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz) - return ErrorOr<StringView>{-1}; +constexpr const char *kProtos[] = { + "https", // http with the secure. + "http", // http without the secure + "file", // filesystem protocol + "ftp", // file transfer protocol + "params", // system settings + "rsh", // remote shell (gui) +}; - ErrorOr<StringView> view{ -1 }; - - return view; - } +constexpr const int kUrlOutSz = 3; //! :// +constexpr const int kProtosCount = 8; +constexpr const int kRangeSz = 4096; + +static ErrorOr<StringView> url_extract_location(const char *url) { + if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz) + return ErrorOr<StringView>{-1}; - Ref<ErrorOr<StringView>> Url::Location() noexcept - { - const char *src = m_urlView.Leak().CData(); - auto loc = url_extract_location(src); + StringView view(string_length(url)); - if (!loc) - return {}; + SizeT i = 0; + bool scheme_found = false; - return Ref<ErrorOr<StringView>>(loc); + for (; i < string_length(url); ++i) { + if (!scheme_found) { + for (int y = 0; kProtosCount; ++y) { + if (string_in_string(view.CData(), kProtos[y])) { + i += string_length(kProtos[y]) + kUrlOutSz; + scheme_found = true; + + break; + } + } } - Ref<ErrorOr<StringView>> Url::Protocol() noexcept - { - const char *src = m_urlView.Leak().CData(); - auto loc = url_extract_protocol(src); + view.Data()[i] = url[i]; + } - if (!loc) - return {}; + return ErrorOr<StringView>(view); +} - return Ref<ErrorOr<StringView>>(loc); - } -} // namespace hCore +static ErrorOr<StringView> url_extract_protocol(const char *url) { + if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz) + return ErrorOr<StringView>{-1}; + + ErrorOr<StringView> view{-1}; + + return view; +} + +Ref<ErrorOr<StringView>> Url::Location() noexcept { + const char *src = m_urlView.Leak().CData(); + auto loc = url_extract_location(src); + + if (!loc) return {}; + + return Ref<ErrorOr<StringView>>(loc); +} + +Ref<ErrorOr<StringView>> Url::Protocol() noexcept { + const char *src = m_urlView.Leak().CData(); + auto loc = url_extract_protocol(src); + + if (!loc) return {}; + + return Ref<ErrorOr<StringView>>(loc); +} +} // namespace hCore diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx new file mode 100644 index 00000000..e748e315 --- /dev/null +++ b/Private/Source/UserHeap.cxx @@ -0,0 +1,188 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include <NewKit/PageManager.hpp> +#include <NewKit/UserHeap.hpp> + +/// @file Heap.cxx +/// @brief Heap Manager, user mode allocator. +/// @note if you want to look at kernel allocs, please look for KHeap.cxx +/// bugs: 0 + +namespace hCore { +class HeapManager final { + public: + static SizeT& GetCount() { return s_NumPools; } + static Ref<Pmm>& GetPmm() { return s_Pmm; } + static Boolean& IsEnabled() { return s_PoolsAreEnabled; } + static Array<Ref<PTEWrapper*>, kPoolMaxSz>& The() { return s_Pool; } + + private: + static Size s_NumPools; + static Ref<Pmm> s_Pmm; + + private: + static Boolean s_PoolsAreEnabled; + static Array<Ref<PTEWrapper*>, kPoolMaxSz> s_Pool; +}; + +//! declare fields + +SizeT HeapManager::s_NumPools = 0UL; +Ref<Pmm> HeapManager::s_Pmm; +Boolean HeapManager::s_PoolsAreEnabled = true; +Array<Ref<PTEWrapper*>, kPoolMaxSz> HeapManager::s_Pool; + +static voidPtr ke_find_unused_heap(Int flags); +static void ke_free_heap_internal(voidPtr vaddr); +static voidPtr ke_make_heap(voidPtr vaddr, Int flags); +static bool ke_check_and_free_heap(const SizeT& index, voidPtr ptr); + +static voidPtr ke_find_unused_heap(Int flags) { + for (SizeT index = 0; index < kPoolMaxSz; ++index) { + if (HeapManager::The()[index] && + !HeapManager::The()[index].Leak().Leak().Leak()->Present()) { + HeapManager::GetPmm().Leak().TogglePresent( + HeapManager::The()[index].Leak().Leak(), true); + kcout << "[ke_find_unused_heap] Done, trying now to make a pool\r\n"; + + return ke_make_heap((voidPtr)HeapManager::The()[index] + .Leak() + .Leak() + .Leak() + ->VirtualAddress(), + flags); + } + } + + return nullptr; +} + +static voidPtr ke_make_heap(voidPtr virtualAddress, Int flags) { + if (virtualAddress) { + HeapHeader* pool_hdr = reinterpret_cast<HeapHeader*>(virtualAddress); + + if (!pool_hdr->Free) { + kcout << "[ke_make_heap] pool_hdr->Free, Pool already exists\n"; + return nullptr; + } + + pool_hdr->Flags = flags; + pool_hdr->Magic = kPoolMag; + pool_hdr->Free = false; + + kcout << "[ke_make_heap] New allocation has been done.\n"; + return reinterpret_cast<voidPtr>( + (reinterpret_cast<UIntPtr>(virtualAddress) + sizeof(HeapHeader))); + } + + kcout << "[ke_make_heap] Address is invalid"; + return nullptr; +} + +static void ke_free_heap_internal(voidPtr virtualAddress) { + HeapHeader* pool_hdr = reinterpret_cast<HeapHeader*>( + reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(HeapHeader)); + + if (pool_hdr->Magic == kPoolMag) { + pool_hdr->Free = false; + pool_hdr->Flags = 0; + + kcout << "[ke_free_heap_internal] Successfully marked header as free!\r\n"; + } +} + +static bool ke_check_and_free_heap(const SizeT& index, voidPtr ptr) { + if (HeapManager::The()[index]) { + // ErrorOr<>::operator bool + if (!HeapManager::The()[index].Leak().Leak().IsStrong()) { + // we want them to be weak + // because we allocated it. + if (HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress() == + (UIntPtr)ptr) { + HeapManager::GetPmm().Leak().FreePage( + HeapManager::The()[index].Leak().Leak()); + --HeapManager::GetCount(); + + ke_free_heap_internal(ptr); + ptr = nullptr; + + return true; + } + } + } + + return false; +} + +/// @brief Creates a new pool pointer. +/// @param flags the flags attached to it. +/// @return a pool pointer with selected permissions. +voidPtr pool_new_ptr(Int32 flags) { + if (!HeapManager::IsEnabled()) return nullptr; + + if (HeapManager::GetCount() > kPoolMaxSz) return nullptr; + + if (voidPtr ret = ke_find_unused_heap(flags)) return ret; + + // this wasn't set to true + auto ref_page = HeapManager::GetPmm().Leak().RequestPage( + ((flags & kPoolUser)), (flags & kPoolRw)); + if (ref_page) { + ///! reserve page. + HeapManager::The()[HeapManager::GetCount()].Leak() = ref_page; + auto& ref = HeapManager::GetCount(); + ++ref; // increment the number of addresses we have now. + + kcout << "[pool_new_ptr] New Address found!\r\n"; + + // finally make the pool address. + return ke_make_heap( + reinterpret_cast<voidPtr>(ref_page.Leak()->VirtualAddress()), flags); + } + + return nullptr; +} + +/// @brief free a pool pointer. +/// @param ptr The pool pointer to free. +/// @return status code +Int32 pool_free_ptr(voidPtr ptr) { + if (!HeapManager::IsEnabled()) return -1; + + if (ptr) { + SizeT base = HeapManager::GetCount(); + + if (ke_check_and_free_heap(base, ptr)) return 0; + + for (SizeT index = 0; index < kPoolMaxSz; ++index) { + if (ke_check_and_free_heap(index, ptr)) return 0; + + --base; + } + } + + return -1; +} + +/// @brief Checks if pointer is valid. +/// @param thePool the pool pointer. +/// @param thePtr the pointer. +/// @param theLimit the last address of the pool. +/// @return if it is valid. +Boolean pool_ptr_exists(UIntPtr thePool, UIntPtr thePtr, SizeT theLimit) { + if (HeapManager::GetCount() < 1) return false; + + if (thePool == 0 || thePtr == 0 || theLimit == 0) { + return false; + } + + return ((thePool) < (thePtr) < (theLimit)); +} +} // namespace hCore diff --git a/Private/Source/Utils.cxx b/Private/Source/Utils.cxx index 9f767d72..6569258b 100644 --- a/Private/Source/Utils.cxx +++ b/Private/Source/Utils.cxx @@ -9,211 +9,166 @@ #include <NewKit/Utils.hpp> -namespace hCore -{ - Int string_compare(const Char *src, const Char *cmp, Size size) - { - Int32 counter = 0; - - for (Size index = 0; index < size; ++index) - { - if (src[index] != cmp[index]) - ++counter; - } - - return counter; - } +namespace hCore { +Int string_compare(const Char *src, const Char *cmp, Size size) { + Int32 counter = 0; - void rt_zero_memory(voidPtr pointer, Size len) - { - rt_set_memory((voidPtr) pointer, 0, len); - } + for (Size index = 0; index < size; ++index) { + if (src[index] != cmp[index]) ++counter; + } - Size string_length(const Char *str, SizeT _len) - { - if (*str == '\0') - return 0; + return counter; +} - Size len{0}; - while (str[len] != '\0') - { - if (len > _len) - { - break; - } +void rt_zero_memory(voidPtr pointer, Size len) { + rt_set_memory((voidPtr)pointer, 0, len); +} - ++len; - } +Size string_length(const Char *str, SizeT _len) { + if (*str == '\0') return 0; - return len; + Size len{0}; + while (str[len] != '\0') { + if (len > _len) { + break; } - Size string_length(const Char *str) - { - if (*str == '\0') - return 0; + ++len; + } - Size len{0}; - while (str[len] != '\0') - ++len; + return len; +} - return len; - } +Size string_length(const Char *str) { + if (*str == '\0') return 0; - voidPtr rt_set_memory(voidPtr src, char value, Size len) - { - if (!src || len < 1) - return nullptr; - char *start = reinterpret_cast<Char*>(src); + Size len{0}; + while (str[len] != '\0') ++len; - while (len) - { - *start = value; - ++start; - --len; - } + return len; +} - return (voidPtr) start; - } +voidPtr rt_set_memory(voidPtr src, char value, Size len) { + if (!src || len < 1) return nullptr; + char *start = reinterpret_cast<Char *>(src); - Int rt_move_memory(const voidPtr src, voidPtr dst, Size len) - { - if (len < 1) - return -2; - if (!src || !dst) - return -1; + while (len) { + *start = value; + ++start; + --len; + } - char *srcChr = reinterpret_cast<Char*>(src); - char *dstChar = reinterpret_cast<Char*>(dst); - Size index = 0; + return (voidPtr)start; +} - while (index < len) - { - dstChar[index] = srcChr[index]; - srcChr[index] = 0; +Int rt_move_memory(const voidPtr src, voidPtr dst, Size len) { + if (len < 1) return -2; + if (!src || !dst) return -1; - index++; - } + char *srcChr = reinterpret_cast<Char *>(src); + char *dstChar = reinterpret_cast<Char *>(dst); + Size index = 0; - return 0; - } + while (index < len) { + dstChar[index] = srcChr[index]; + srcChr[index] = 0; - Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) - { - if (len < 1) - return -2; - if (!src || !dst) - return -1; + index++; + } - char *srcChr = reinterpret_cast<char*>(src); - char *dstChar = reinterpret_cast<char*>(dst); - Size index = 0; + return 0; +} - while (index < len) - { - dstChar[index] = srcChr[index]; - index++; - } +Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { + if (len < 1) return -2; + if (!src || !dst) return -1; - return 0; - } + char *srcChr = reinterpret_cast<char *>(src); + char *dstChar = reinterpret_cast<char *>(dst); + Size index = 0; - const Char *alloc_string(const Char *text) - { - if (!text) - return nullptr; + while (index < len) { + dstChar[index] = srcChr[index]; + index++; + } - const Char *string = new Char[string_length(text)]; - if (!string) - return nullptr; + return 0; +} - voidPtr vText = reinterpret_cast<voidPtr>(const_cast<char*>(text)); - voidPtr vStr = reinterpret_cast<voidPtr>(const_cast<char*>(string)); - rt_copy_memory(vText, vStr, string_length(text)); - return string; - } +const Char *alloc_string(const Char *text) { + if (!text) return nullptr; - Int to_uppercase(Int character) - { - if (character >= 'a' && character <= 'z') - return character - 0x20; + const Char *string = new Char[string_length(text)]; + if (!string) return nullptr; - return character; - } + voidPtr vText = reinterpret_cast<voidPtr>(const_cast<char *>(text)); + voidPtr vStr = reinterpret_cast<voidPtr>(const_cast<char *>(string)); + rt_copy_memory(vText, vStr, string_length(text)); + return string; +} - Int to_lower(Int character) - { - if (character >= 'A' && character <= 'Z') - return character + 0x20; +Int to_uppercase(Int character) { + if (character >= 'a' && character <= 'z') return character - 0x20; - return character; - } + return character; +} - bool to_str(Char *str, Int limit, Int base) - { - if (limit == 0) - return false; +Int to_lower(Int character) { + if (character >= 'A' && character <= 'Z') return character + 0x20; - Int copy_limit = limit; - Int cnt = 0; - Int ret = base; + return character; +} - while (limit != 1) { - ret = ret % 10; - str[cnt] = ret; +bool to_str(Char *str, Int limit, Int base) { + if (limit == 0) return false; - ++cnt; - --limit; - --ret; - } + Int copy_limit = limit; + Int cnt = 0; + Int ret = base; - str[copy_limit] = '\0'; - return true; - } + while (limit != 1) { + ret = ret % 10; + str[cnt] = ret; - Boolean is_space(Char chr) - { - return chr == ' '; - } + ++cnt; + --limit; + --ret; + } - Boolean is_newln(Char chr) - { - return chr == '\n'; - } + str[copy_limit] = '\0'; + return true; +} - voidPtr string_in_string(const char *in, const char *needle) - { - for (size_t i = 0; i < string_length(in); ++i) - { - if (string_compare(in + i, needle, string_length(needle)) == 0) - return reinterpret_cast<voidPtr>(const_cast<char*>(in + i)); - } +Boolean is_space(Char chr) { return chr == ' '; } - return nullptr; - } +Boolean is_newln(Char chr) { return chr == '\n'; } - // @brief Checks for a string start at the character. - - char* string_from_char(char* str, const char chr) - { - while (*str != chr) - { - ++str; - - if (*str == 0) - return nullptr; - } - - return str; - } -} // namespace hCore +voidPtr string_in_string(const char *in, const char *needle) { + for (size_t i = 0; i < string_length(in); ++i) { + if (string_compare(in + i, needle, string_length(needle)) == 0) + return reinterpret_cast<voidPtr>(const_cast<char *>(in + i)); + } -extern "C" void memset(void* dst, char src, size_t len) -{ - hCore::rt_set_memory(dst, src, len); + return nullptr; } -extern "C" void memcpy(void* dst, void* src, size_t len) -{ - hCore::rt_copy_memory(src, dst, len); -}
\ No newline at end of file +// @brief Checks for a string start at the character. + +char *string_from_char(char *str, const char chr) { + while (*str != chr) { + ++str; + + if (*str == 0) return nullptr; + } + + return str; +} +} // namespace hCore + +extern "C" void memset(void *dst, char src, size_t len) { + hCore::rt_set_memory(dst, src, len); +} + +extern "C" void memcpy(void *dst, void *src, size_t len) { + hCore::rt_copy_memory(src, dst, len); +} diff --git a/Private/Source/Variant.cxx b/Private/Source/Variant.cxx index 3881a07d..cb1a9a01 100644 --- a/Private/Source/Variant.cxx +++ b/Private/Source/Variant.cxx @@ -9,24 +9,20 @@ #include <NewKit/Variant.hpp> -namespace hCore -{ - const Char* Variant::ToString() - { - if (m_Ptr == nullptr) - { - return ("Memory:{Nullptr}"); - } +namespace hCore { +const Char* Variant::ToString() { + if (m_Ptr == nullptr) { + return ("Memory:{Nullptr}"); + } - switch (m_Kind) - { - case VariantKind::kString: - return ("Class:{String}"); - case VariantKind::kPointer: - return ("Memory:{Pointer}"); - default: - return ("Class:{Undefined}"); - } - } + switch (m_Kind) { + case VariantKind::kString: + return ("Class:{String}"); + case VariantKind::kPointer: + return ("Memory:{Pointer}"); + default: + return ("Class:{Undefined}"); + } +} -} // namespace hCore +} // namespace hCore diff --git a/Private/makefile b/Private/makefile index 7e6a6639..b4245f03 100644 --- a/Private/makefile +++ b/Private/makefile @@ -5,7 +5,7 @@ CC = x86_64-elf-gcc LD = x86_64-elf-ld -CCFLAGS = -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__hCore__ -I../ -I./ -I$(HOME)/ +CCFLAGS = -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I../ -I./ -I$(HOME)/ ASM = nasm ASMFLAGS = -f elf64 @@ -18,12 +18,12 @@ SCRIPT = --script=Linker/Platforms/PC.lds # we want a flat binary FMT = elf64 -.PHONY: kernel-no -kernel-no: - @echo "Use make all instead." +.PHONY: invalid-recipe +invalid-recipe: + @echo "invalid-recipe: Use make all instead." -.PHONY: kernel-build -kernel-build: +.PHONY: h-core +h-core: $(CC) $(CCFLAGS) Source/*.cxx HALKit/AMD64/PCI/*.cpp Source/Network/*.cpp\ Source/Storage/*.cxx HALKit/AMD64/*.cxx HALKit/AMD64/*.cpp HALKit/AMD64/*.s $(ASM) -f elf64 HALKit/AMD64/DebugManager.asm @@ -34,16 +34,16 @@ kernel-build: OBJCOPY = x86_64-elf-objcopy -.PHONY: kernel-link -kernel-link: +.PHONY: link +link: $(LD) $(SCRIPT) Obj/*.o -o $(KERNEL) $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target efi-app-x86_64 --subsystem=10 $(KERNEL) $(KERNEL) cp $(KERNEL) Root/System .PHONY: all -all: kernel-build kernel-link - @echo "[hKernel] Job is done." +all: h-core link + @echo "[hKernel] HCore is linked." -.PHONY: kernel-clean -kernel-clean: +.PHONY: clean +clean: rm -f Obj/*.o $(KERNEL) diff --git a/Public/SDK/SystemKit/FileAPI.hxx b/Public/SDK/SystemKit/FileAPI.hxx index 089a5882..12b57a41 100644 --- a/Public/SDK/SystemKit/FileAPI.hxx +++ b/Public/SDK/SystemKit/FileAPI.hxx @@ -15,27 +15,26 @@ using namespace hCore; -class HFile final -{ - public: - explicit HFile(const char *path); - ~HFile(); - - public: - HCORE_COPY_DEFAULT(HFile); - - public: - void *Read(SizeT off, SizeT sz); - void Write(void *buf, SizeT off, SizeT sz); - void Seek(SizeT off); - void *Read(SizeT sz); - void Write(void *buf, SizeT sz); - void Rewind(); - - public: - void SetMIME(const char *mime); +class HFile final { + public: + explicit HFile(const char *path); + ~HFile(); + + public: + HCORE_COPY_DEFAULT(HFile); + + public: + void *Read(SizeT off, SizeT sz); + void Write(void *buf, SizeT off, SizeT sz); + void Seek(SizeT off); + void *Read(SizeT sz); + void Write(void *buf, SizeT sz); + void Rewind(); + + public: + void SetMIME(const char *mime); }; typedef HFile *HFilePtr; -#endif // ifndef _SYSTEM_KIT_HCORE_FILE_HPP +#endif // ifndef _SYSTEM_KIT_HCORE_FILE_HPP diff --git a/Public/SDK/SystemKit/HeapAPI.hxx b/Public/SDK/SystemKit/HeapAPI.hxx index 8f89235c..aa082ca6 100644 --- a/Public/SDK/SystemKit/HeapAPI.hxx +++ b/Public/SDK/SystemKit/HeapAPI.hxx @@ -18,51 +18,48 @@ class HMemoryException; typedef VoidPtr HHeapPtr; -enum -{ - kHeapExpandable = 2, - kHeapNoExecute = 4, - kHeapShared = 6, - kHeapReadOnly = 8, - kHeapNoFlags = 0 +enum { + kHeapExpandable = 2, + kHeapNoExecute = 4, + kHeapShared = 6, + kHeapReadOnly = 8, + kHeapNoFlags = 0 }; -class HHeap final -{ - private: - explicit HHeap(); +class HHeap final { + private: + explicit HHeap(); - public: - ~HHeap(); + public: + ~HHeap(); - public: - HCORE_COPY_DEFAULT(HHeap); + public: + HCORE_COPY_DEFAULT(HHeap); - public: - static HHeap *Shared() noexcept; + public: + static HHeap *Shared() noexcept; - public: - void Delete(HHeapPtr me) noexcept; - SizeT Tell(HHeapPtr me) noexcept; - HHeapPtr New(const SizeT &sz, const Int32 flags = kHeapNoFlags); + public: + void Delete(HHeapPtr me) noexcept; + SizeT Tell(HHeapPtr me) noexcept; + HHeapPtr New(const SizeT &sz, const Int32 flags = kHeapNoFlags); }; -class HMemoryException final -{ - public: - HMemoryException() = default; - ~HMemoryException() = default; +class HMemoryException final { + public: + HMemoryException() = default; + ~HMemoryException() = default; - public: - HCORE_COPY_DEFAULT(HMemoryException); + public: + HCORE_COPY_DEFAULT(HMemoryException); - public: - const char *Name(); - const char *Reason(); + public: + const char *Name(); + const char *Reason(); - private: - const char *mReason{"Memory error!"}; + private: + const char *mReason{"Memory error!"}; - private: - friend HHeap; + private: + friend HHeap; }; diff --git a/Public/SDK/SystemKit/ThreadAPI.hxx b/Public/SDK/SystemKit/ThreadAPI.hxx index 8d948a35..24fc8507 100644 --- a/Public/SDK/SystemKit/ThreadAPI.hxx +++ b/Public/SDK/SystemKit/ThreadAPI.hxx @@ -16,27 +16,24 @@ #include <NewKit/Defines.hpp> -namespace hCore -{ +namespace hCore { /// @brief Thread Information Block for Local Storage. /// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64) -struct ThreadInformationBlock final -{ - const Char TIB_NAME[255]; // Module Name - const UIntPtr TIB_START_CODE; // Start Address - const UIntPtr TIB_START_ALLOC; // Allocation Heap - const UIntPtr TIB_START_STACK; // Stack Pointer. - const Int32 TIB_ARCH; // Architecture and/or platform. +struct ThreadInformationBlock final { + const Char TIB_NAME[255]; // Module Name + const UIntPtr TIB_START_CODE; // Start Address + const UIntPtr TIB_START_ALLOC; // Allocation Heap + const UIntPtr TIB_START_STACK; // Stack Pointer. + const Int32 TIB_ARCH; // Architecture and/or platform. }; -enum -{ - kPC_IA64, - kPC_AMD64 = kPC_IA64, - kPC_ARM, - kMACS_64x0, - kMACS_32x0, +enum { + kPC_IA64, + kPC_AMD64 = kPC_IA64, + kPC_ARM, + kMACS_64x0, + kMACS_32x0, }; -} // namespace hCore +} // namespace hCore -#endif // __THREAD_API__ +#endif // __THREAD_API__ diff --git a/Public/SDK/UIKit/UIKitCore.cxx b/Public/SDK/UIKit/UIKitCore.cxx deleted file mode 100644 index e43f5a14..00000000 --- a/Public/SDK/UIKit/UIKitCore.cxx +++ /dev/null @@ -1,11 +0,0 @@ -/* - * ======================================================== - * - * hCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include "UIKitCore.hxx" - diff --git a/Public/SDK/UIKit/UIKitCore.hxx b/Public/SDK/UIKit/UIKitCore.hxx deleted file mode 100644 index 05274e97..00000000 --- a/Public/SDK/UIKit/UIKitCore.hxx +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ======================================================== - * - * hCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#pragma once - -#include <NewKit/Defines.hpp> - -namespace hCore -{ - //! @brief Window Delegate system. - class CWindowDelegate - { - public: - CWindowDelegate() = default; - ~CWindowDelegate() = default; - - public: - CWindowDelegate& operator=(const CWindowDelegate&) = default; - CWindowDelegate(const CWindowDelegate&) = default; - - virtual void DispatchMessage(UInt32, VoidPtr, SizeT) = 0; - - }; - - typedef CWindowDelegate* CWindowDelegatePtr; - - //! @brief A Window message manager. - //! Takes care of sending message and delegates data to the window. - class CWindowMessage final - { - public: - explicit CWindowMessage() = default; - ~CWindowMessage() = default; - - CWindowMessage& operator=(const CWindowMessage&) = default; - CWindowMessage(const CWindowMessage&) = default; - - //! @brief updates window with message, rpc data, and it's size. - inline void operator()(UInt32 msg, VoidPtr rpc, SizeT rpcSize) - { - fWindowDelegate->DispatchMessage(msg, rpc, rpcSize); - } - - CWindowDelegatePtr fWindowDelegate; - - }; - - typedef VoidPtr CWindowRef; -} diff --git a/Public/SDK/UIKit/UILookAndFeel+UIDC.cxx b/Public/SDK/UIKit/UILookAndFeel+UIDC.cxx deleted file mode 100644 index b4745d7b..00000000 --- a/Public/SDK/UIKit/UILookAndFeel+UIDC.cxx +++ /dev/null @@ -1,10 +0,0 @@ -/* - * ======================================================== - * - * hCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include "UILookAndFeel+UIDC.hxx" diff --git a/Public/SDK/UIKit/UILookAndFeel+UIDC.hxx b/Public/SDK/UIKit/UILookAndFeel+UIDC.hxx deleted file mode 100644 index 75642b50..00000000 --- a/Public/SDK/UIKit/UILookAndFeel+UIDC.hxx +++ /dev/null @@ -1,142 +0,0 @@ -/* - * ======================================================== - * - * hCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#pragma once - -#include <UIKit/UIKitCore.hxx> - -namespace hCore -{ -// -// @brief Window Device Context. -// Takes care of drawing the stuff. -// - -class CWindowDC -{ - public: - explicit CWindowDC() = default; - virtual ~CWindowDC() = default; - - CWindowDC &operator=(const CWindowDC &) = default; - CWindowDC(const CWindowDC &) = default; - - public: - //! @brief Draws a rectangle. - //! label: text to show. - //! x: x position. - //! y: y position. - //! w: width - //! h: height - virtual bool DrawRectangle(Int32 x, Int32 y, Int32 w, Int32 h, Int32 r, Int32 g, Int32 b, Int32 a) = 0; - - //! @brief Draws circles.. - //! x: x position. - //! y: y position. - //! enable: enable control. - virtual bool DrawCircle(Int32 x, Int32 y, Int32 w, Int32 h, float radius) = 0; - - //! @brief Draws text. - //! x: x position. - //! y: y position. - virtual bool DrawText(const char *text, Int32 x, Int32 y, Int32 w, Int32 h) = 0; - - //! @brief Draws an icon - //! x: x position. - //! y: y position. - //! w: width - //! h: height - //! sz: size of icon - //! icon: icon pointer. - virtual bool DrawIcon(VoidPtr icon, SizeT sz, Int32 y, Int32 w, Int32 h, Int32 bpp); -}; - -// -// @brief Window Look and feel class. -// Takes care of drawing the stuff. -// - -class CWindowLookAndFeel -{ - public: - CWindowLookAndFeel() = default; - virtual ~CWindowLookAndFeel() = default; - - CWindowLookAndFeel &operator=(const CWindowLookAndFeel &) = default; - CWindowLookAndFeel(const CWindowLookAndFeel &) = default; - - public: - //! @brief Draw button virtual method. - //! label: text to show. - //! x: x position. - //! y: y position. - //! w: width - //! h: height - virtual bool DrawButton(const char *label, Int32 x, Int32 y, Int32 w, Int32 h) = 0; - - //! @brief Draw button (hovered) virtual method. - //! label: text to show. - //! x: x position. - //! y: y position. - //! w: width - //! h: height - virtual bool DrawButtonHovered(const char *label, Int32 x, Int32 y, Int32 w, Int32 h) = 0; - - //! @brief Draws a radio checkbox. - //! x: x position. - //! y: y position. - //! enable: enable control. - virtual bool DrawRadio(const bool enable, Int32 x, Int32 y) = 0; - - //! @brief Draws a check-box. - //! x: x position. - //! y: y position. - virtual bool DrawCheckbox(const bool enable, Int32 x, Int32 y) = 0; - - //! @brief Draws a textbox. - //! x: x position. - //! y: y position. - virtual bool DrawTextBox(const char *content, Int32 x, Int32 y, Int32 w, Int32 h) = 0; - - //! @brief Draws a window. - //! x: x position. - //! y: y position. - virtual bool DrawWindow(const char *title, Int32 x, Int32 y, Int32 w, Int32 h) = 0; - - //! @brief Draws a window in focused mode. - //! x: x position. - //! y: y position. - virtual bool DrawWindowFocused(const char *title, Int32 x, Int32 y, Int32 w, Int32 h) = 0; - - // does something similar to this. - // ----- MY GROUP NAME -------------- - // | THIS IS A LABEL | - // | | - // | | BUTTON | | - // |--------------------------------- - virtual bool DrawGroupBox(const char *title) = 0; - - // This enum is telling how to draw the cursor - enum - { - kQuestion, - kPointer, - kSelection, - kText, - }; - - virtual bool DrawCursor(Int32 x, Int32 y, Int32 type) = 0; -}; -} // namespace hCore - -// These macros are used to pass colors as arguments. -// pDC->DrawRectangle(0, 0, 10, 10, RgbArg(255, 255, 255)); - -#define RgbArg(R, G, B) R / 255, G / 255, B / 255 -#define RgbaArg(R, G, B, A) RgbArg(R, G, B), A / 255 diff --git a/Public/SDK/UIKit/makefile b/Public/SDK/UIKit/makefile deleted file mode 100644 index 103bc0c8..00000000 --- a/Public/SDK/UIKit/makefile +++ /dev/null @@ -1,21 +0,0 @@ -################################################## -# ; (C) Mahrouss Logic, 2024, all rights reserved. -# This is the UIKit Makefile. -################################################## - -CC=x86_64-w64-mingw32-g++ -CCFLAGS=-c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -ASM=nasm -ASMFLAGS=-f elf64 - -.PHONY: build_uikit -build_uikit: - $(CC) -I../ -I../../../Private/ $(CCFLAGS) *.cxx - -.PHONY: all -all: build_uikit - @echo "Done." - -.PHONY: clean -clean: - rm -f *.o diff --git a/Public/SDK/ZipKit/NewFS-Addon.hpp b/Public/SDK/ZipKit/NewFS-Addon.hpp index de308389..0325f81e 100644 --- a/Public/SDK/ZipKit/NewFS-Addon.hpp +++ b/Public/SDK/ZipKit/NewFS-Addon.hpp @@ -16,4 +16,3 @@ // NewFS catalog has password attached to it. #define kNewFSHasPassword 256 - diff --git a/Public/SDK/ZipKit/Zip.cxx b/Public/SDK/ZipKit/Zip.cxx index 79788a8e..71523143 100644 --- a/Public/SDK/ZipKit/Zip.cxx +++ b/Public/SDK/ZipKit/Zip.cxx @@ -14,67 +14,64 @@ #define kInitialSz 4096 -namespace ZipKit -{ -ZipStream::ZipStream() : fSharedData(HHeap::Shared()->New(kInitialSz, kHeapExpandable)), fSharedSz(kInitialSz) -{ -} +namespace ZipKit { +ZipStream::ZipStream() + : fSharedData(HHeap::Shared()->New(kInitialSz, kHeapExpandable)), + fSharedSz(kInitialSz) {} -ZipStream::~ZipStream() noexcept -{ - if (fSharedData) - HHeap::Shared()->Delete(fSharedData); +ZipStream::~ZipStream() noexcept { + if (fSharedData) HHeap::Shared()->Delete(fSharedData); } -HFilePtr ZipStream::FlushToFile(const char *name) -{ - HFilePtr fp = new HFile(name); - MUST_PASS(fp); +HFilePtr ZipStream::FlushToFile(const char *name) { + HFilePtr fp = new HFile(name); + MUST_PASS(fp); - this->fSharedSz = HHeap::Shared()->Tell(this->fSharedData); + this->fSharedSz = HHeap::Shared()->Tell(this->fSharedData); - fp->SetMIME("application/x-bzip"); - fp->Write(this->fSharedData, this->fSharedSz); + fp->SetMIME("application/x-bzip"); + fp->Write(this->fSharedData, this->fSharedSz); - return fp; + return fp; } -void *ZipStream::Deflate(const char *name) -{ - z_stream deflate_stream{0}; +void *ZipStream::Deflate(const char *name) { + z_stream deflate_stream{0}; - deflate_stream.zalloc = Z_NULL; - deflate_stream.zfree = Z_NULL; - deflate_stream.opaque = Z_NULL; + deflate_stream.zalloc = Z_NULL; + deflate_stream.zfree = Z_NULL; + deflate_stream.opaque = Z_NULL; - deflate_stream.avail_in = (uInt)this->fSharedSz + 1; // size of input, string + terminator - deflate_stream.next_in = (Bytef *)this->fSharedData; // input char array - deflate_stream.avail_out = (uInt)this->fSharedSz; // size of output - deflate_stream.next_out = (Bytef *)this->fSharedData; // output char array + deflate_stream.avail_in = + (uInt)this->fSharedSz + 1; // size of input, string + terminator + deflate_stream.next_in = (Bytef *)this->fSharedData; // input char array + deflate_stream.avail_out = (uInt)this->fSharedSz; // size of output + deflate_stream.next_out = (Bytef *)this->fSharedData; // output char array - deflateInit(&deflate_stream, 1); - deflate(&deflate_stream, Z_NO_FLUSH); - deflateEnd(&deflate_stream); + deflateInit(&deflate_stream, 1); + deflate(&deflate_stream, Z_NO_FLUSH); + deflateEnd(&deflate_stream); - return this->fSharedData; + return this->fSharedData; } -void ZipStream::Inflate(const char *name, void *data) -{ - z_stream inflate_stream{0}; +void ZipStream::Inflate(const char *name, void *data) { + z_stream inflate_stream{0}; - inflate_stream.zalloc = Z_NULL; - inflate_stream.zfree = Z_NULL; - inflate_stream.opaque = Z_NULL; + inflate_stream.zalloc = Z_NULL; + inflate_stream.zfree = Z_NULL; + inflate_stream.opaque = Z_NULL; - inflate_stream.avail_in = (SizeT)((char *)(inflate_stream.next_out - (Bytef *)this->fSharedData)); // size of input + inflate_stream.avail_in = + (SizeT)((char *)(inflate_stream.next_out - + (Bytef *)this->fSharedData)); // size of input - inflate_stream.next_in = (Bytef *)this->fSharedData; // input char array - inflate_stream.avail_out = (uInt)this->fSharedSz; // size of output - inflate_stream.next_out = (Bytef *)this->fSharedData; // output char array + inflate_stream.next_in = (Bytef *)this->fSharedData; // input char array + inflate_stream.avail_out = (uInt)this->fSharedSz; // size of output + inflate_stream.next_out = (Bytef *)this->fSharedData; // output char array - inflateInit(&inflate_stream); - inflate(&inflate_stream, Z_NO_FLUSH); - inflateEnd(&inflate_stream); + inflateInit(&inflate_stream); + inflate(&inflate_stream, Z_NO_FLUSH); + inflateEnd(&inflate_stream); } -} // namespace ZipKit +} // namespace ZipKit diff --git a/Public/SDK/ZipKit/Zip.hpp b/Public/SDK/ZipKit/Zip.hpp index 0130a021..91ecde51 100644 --- a/Public/SDK/ZipKit/Zip.hpp +++ b/Public/SDK/ZipKit/Zip.hpp @@ -11,34 +11,31 @@ #define Z_SOLO 1 -#include <ZipKit/Defines.hpp> - #include <CompilerKit/Compiler.hpp> +#include <ZipKit/Defines.hpp> #include <ZipKit/zlib.hpp> -namespace ZipKit -{ +namespace ZipKit { class ZipStream; -class ZipStream final -{ - public: - explicit ZipStream(); - ~ZipStream() noexcept; +class ZipStream final { + public: + explicit ZipStream(); + ~ZipStream() noexcept; - public: - HCORE_COPY_DEFAULT(ZipStream); + public: + HCORE_COPY_DEFAULT(ZipStream); - public: - HFilePtr FlushToFile(const char *name); - void *Deflate(const char *name); - void Inflate(const char *name, void *data); + public: + HFilePtr FlushToFile(const char *name); + void *Deflate(const char *name); + void Inflate(const char *name, void *data); - private: - VoidPtr fSharedData{nullptr}; - SizeT fSharedSz{0}; + private: + VoidPtr fSharedData{nullptr}; + SizeT fSharedSz{0}; - private: - z_stream fStream; + private: + z_stream fStream; }; -} // namespace ZipKit +} // namespace ZipKit diff --git a/Public/SDK/ZipKit/zconf.hpp b/Public/SDK/ZipKit/zconf.hpp index 0eb08624..14ab12d7 100644 --- a/Public/SDK/ZipKit/zconf.hpp +++ b/Public/SDK/ZipKit/zconf.hpp @@ -14,177 +14,177 @@ * Even better than compiling with -DZ_PREFIX would be to use configure to set * this permanently in zconf.h using "./configure --zprefix". */ -#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ -# define Z_PREFIX_SET +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +#define Z_PREFIX_SET /* all linked symbols and init macros */ -# define _dist_code z__dist_code -# define _length_code z__length_code -# define _tr_align z__tr_align -# define _tr_flush_bits z__tr_flush_bits -# define _tr_flush_block z__tr_flush_block -# define _tr_init z__tr_init -# define _tr_stored_block z__tr_stored_block -# define _tr_tally z__tr_tally -# define adler32 z_adler32 -# define adler32_combine z_adler32_combine -# define adler32_combine64 z_adler32_combine64 -# define adler32_z z_adler32_z -# ifndef Z_SOLO -# define compress z_compress -# define compress2 z_compress2 -# define compressBound z_compressBound -# endif -# define crc32 z_crc32 -# define crc32_combine z_crc32_combine -# define crc32_combine64 z_crc32_combine64 -# define crc32_z z_crc32_z -# define deflate z_deflate -# define deflateBound z_deflateBound -# define deflateCopy z_deflateCopy -# define deflateEnd z_deflateEnd -# define deflateGetDictionary z_deflateGetDictionary -# define deflateInit z_deflateInit -# define deflateInit2 z_deflateInit2 -# define deflateInit2_ z_deflateInit2_ -# define deflateInit_ z_deflateInit_ -# define deflateParams z_deflateParams -# define deflatePending z_deflatePending -# define deflatePrime z_deflatePrime -# define deflateReset z_deflateReset -# define deflateResetKeep z_deflateResetKeep -# define deflateSetDictionary z_deflateSetDictionary -# define deflateSetHeader z_deflateSetHeader -# define deflateTune z_deflateTune -# define deflate_copyright z_deflate_copyright -# define get_crc_table z_get_crc_table -# ifndef Z_SOLO -# define gz_error z_gz_error -# define gz_intmax z_gz_intmax -# define gz_strwinerror z_gz_strwinerror -# define gzbuffer z_gzbuffer -# define gzclearerr z_gzclearerr -# define gzclose z_gzclose -# define gzclose_r z_gzclose_r -# define gzclose_w z_gzclose_w -# define gzdirect z_gzdirect -# define gzdopen z_gzdopen -# define gzeof z_gzeof -# define gzerror z_gzerror -# define gzflush z_gzflush -# define gzfread z_gzfread -# define gzfwrite z_gzfwrite -# define gzgetc z_gzgetc -# define gzgetc_ z_gzgetc_ -# define gzgets z_gzgets -# define gzoffset z_gzoffset -# define gzoffset64 z_gzoffset64 -# define gzopen z_gzopen -# define gzopen64 z_gzopen64 -# ifdef _WIN32 -# define gzopen_w z_gzopen_w -# endif -# define gzprintf z_gzprintf -# define gzputc z_gzputc -# define gzputs z_gzputs -# define gzread z_gzread -# define gzrewind z_gzrewind -# define gzseek z_gzseek -# define gzseek64 z_gzseek64 -# define gzsetparams z_gzsetparams -# define gztell z_gztell -# define gztell64 z_gztell64 -# define gzungetc z_gzungetc -# define gzvprintf z_gzvprintf -# define gzwrite z_gzwrite -# endif -# define inflate z_inflate -# define inflateBack z_inflateBack -# define inflateBackEnd z_inflateBackEnd -# define inflateBackInit z_inflateBackInit -# define inflateBackInit_ z_inflateBackInit_ -# define inflateCodesUsed z_inflateCodesUsed -# define inflateCopy z_inflateCopy -# define inflateEnd z_inflateEnd -# define inflateGetDictionary z_inflateGetDictionary -# define inflateGetHeader z_inflateGetHeader -# define inflateInit z_inflateInit -# define inflateInit2 z_inflateInit2 -# define inflateInit2_ z_inflateInit2_ -# define inflateInit_ z_inflateInit_ -# define inflateMark z_inflateMark -# define inflatePrime z_inflatePrime -# define inflateReset z_inflateReset -# define inflateReset2 z_inflateReset2 -# define inflateResetKeep z_inflateResetKeep -# define inflateSetDictionary z_inflateSetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateUndermine z_inflateUndermine -# define inflateValidate z_inflateValidate -# define inflate_copyright z_inflate_copyright -# define inflate_fast z_inflate_fast -# define inflate_table z_inflate_table -# ifndef Z_SOLO -# define uncompress z_uncompress -# define uncompress2 z_uncompress2 -# endif -# define zError z_zError -# ifndef Z_SOLO -# define zcalloc z_zcalloc -# define zcfree z_zcfree -# endif -# define zlibCompileFlags z_zlibCompileFlags -# define zlibVersion z_zlibVersion +#define _dist_code z__dist_code +#define _length_code z__length_code +#define _tr_align z__tr_align +#define _tr_flush_bits z__tr_flush_bits +#define _tr_flush_block z__tr_flush_block +#define _tr_init z__tr_init +#define _tr_stored_block z__tr_stored_block +#define _tr_tally z__tr_tally +#define adler32 z_adler32 +#define adler32_combine z_adler32_combine +#define adler32_combine64 z_adler32_combine64 +#define adler32_z z_adler32_z +#ifndef Z_SOLO +#define compress z_compress +#define compress2 z_compress2 +#define compressBound z_compressBound +#endif +#define crc32 z_crc32 +#define crc32_combine z_crc32_combine +#define crc32_combine64 z_crc32_combine64 +#define crc32_z z_crc32_z +#define deflate z_deflate +#define deflateBound z_deflateBound +#define deflateCopy z_deflateCopy +#define deflateEnd z_deflateEnd +#define deflateGetDictionary z_deflateGetDictionary +#define deflateInit z_deflateInit +#define deflateInit2 z_deflateInit2 +#define deflateInit2_ z_deflateInit2_ +#define deflateInit_ z_deflateInit_ +#define deflateParams z_deflateParams +#define deflatePending z_deflatePending +#define deflatePrime z_deflatePrime +#define deflateReset z_deflateReset +#define deflateResetKeep z_deflateResetKeep +#define deflateSetDictionary z_deflateSetDictionary +#define deflateSetHeader z_deflateSetHeader +#define deflateTune z_deflateTune +#define deflate_copyright z_deflate_copyright +#define get_crc_table z_get_crc_table +#ifndef Z_SOLO +#define gz_error z_gz_error +#define gz_intmax z_gz_intmax +#define gz_strwinerror z_gz_strwinerror +#define gzbuffer z_gzbuffer +#define gzclearerr z_gzclearerr +#define gzclose z_gzclose +#define gzclose_r z_gzclose_r +#define gzclose_w z_gzclose_w +#define gzdirect z_gzdirect +#define gzdopen z_gzdopen +#define gzeof z_gzeof +#define gzerror z_gzerror +#define gzflush z_gzflush +#define gzfread z_gzfread +#define gzfwrite z_gzfwrite +#define gzgetc z_gzgetc +#define gzgetc_ z_gzgetc_ +#define gzgets z_gzgets +#define gzoffset z_gzoffset +#define gzoffset64 z_gzoffset64 +#define gzopen z_gzopen +#define gzopen64 z_gzopen64 +#ifdef _WIN32 +#define gzopen_w z_gzopen_w +#endif +#define gzprintf z_gzprintf +#define gzputc z_gzputc +#define gzputs z_gzputs +#define gzread z_gzread +#define gzrewind z_gzrewind +#define gzseek z_gzseek +#define gzseek64 z_gzseek64 +#define gzsetparams z_gzsetparams +#define gztell z_gztell +#define gztell64 z_gztell64 +#define gzungetc z_gzungetc +#define gzvprintf z_gzvprintf +#define gzwrite z_gzwrite +#endif +#define inflate z_inflate +#define inflateBack z_inflateBack +#define inflateBackEnd z_inflateBackEnd +#define inflateBackInit z_inflateBackInit +#define inflateBackInit_ z_inflateBackInit_ +#define inflateCodesUsed z_inflateCodesUsed +#define inflateCopy z_inflateCopy +#define inflateEnd z_inflateEnd +#define inflateGetDictionary z_inflateGetDictionary +#define inflateGetHeader z_inflateGetHeader +#define inflateInit z_inflateInit +#define inflateInit2 z_inflateInit2 +#define inflateInit2_ z_inflateInit2_ +#define inflateInit_ z_inflateInit_ +#define inflateMark z_inflateMark +#define inflatePrime z_inflatePrime +#define inflateReset z_inflateReset +#define inflateReset2 z_inflateReset2 +#define inflateResetKeep z_inflateResetKeep +#define inflateSetDictionary z_inflateSetDictionary +#define inflateSync z_inflateSync +#define inflateSyncPoint z_inflateSyncPoint +#define inflateUndermine z_inflateUndermine +#define inflateValidate z_inflateValidate +#define inflate_copyright z_inflate_copyright +#define inflate_fast z_inflate_fast +#define inflate_table z_inflate_table +#ifndef Z_SOLO +#define uncompress z_uncompress +#define uncompress2 z_uncompress2 +#endif +#define zError z_zError +#ifndef Z_SOLO +#define zcalloc z_zcalloc +#define zcfree z_zcfree +#endif +#define zlibCompileFlags z_zlibCompileFlags +#define zlibVersion z_zlibVersion /* all zlib typedefs in zlib.h and zconf.h */ -# define Byte z_Byte -# define Bytef z_Bytef -# define alloc_func z_alloc_func -# define charf z_charf -# define free_func z_free_func -# ifndef Z_SOLO -# define gzFile z_gzFile -# endif -# define gz_header z_gz_header -# define gz_headerp z_gz_headerp -# define in_func z_in_func -# define intf z_intf -# define out_func z_out_func -# define uInt z_uInt -# define uIntf z_uIntf -# define uLong z_uLong -# define uLongf z_uLongf -# define voidp z_voidp -# define voidpc z_voidpc -# define voidpf z_voidpf +#define Byte z_Byte +#define Bytef z_Bytef +#define alloc_func z_alloc_func +#define charf z_charf +#define free_func z_free_func +#ifndef Z_SOLO +#define gzFile z_gzFile +#endif +#define gz_header z_gz_header +#define gz_headerp z_gz_headerp +#define in_func z_in_func +#define intf z_intf +#define out_func z_out_func +#define uInt z_uInt +#define uIntf z_uIntf +#define uLong z_uLong +#define uLongf z_uLongf +#define voidp z_voidp +#define voidpc z_voidpc +#define voidpf z_voidpf /* all zlib structs in zlib.h and zconf.h */ -# define gz_header_s z_gz_header_s -# define internal_state z_internal_state +#define gz_header_s z_gz_header_s +#define internal_state z_internal_state #endif #if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS +#define MSDOS #endif #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) -# define OS2 +#define OS2 #endif #if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS +#define WINDOWS #endif #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) -# ifndef WIN32 -# define WIN32 -# endif +#ifndef WIN32 +#define WIN32 +#endif #endif #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) -# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) -# ifndef SYS16BIT -# define SYS16BIT -# endif -# endif +#if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +#ifndef SYS16BIT +#define SYS16BIT +#endif +#endif #endif /* @@ -192,73 +192,73 @@ * than 64k bytes at a time (needed on systems with 16-bit int). */ #ifdef SYS16BIT -# define MAXSEG_64K +#define MAXSEG_64K #endif #ifdef MSDOS -# define UNALIGNED_OK +#define UNALIGNED_OK #endif #ifdef __STDC_VERSION__ -# ifndef STDC -# define STDC -# endif -# if __STDC_VERSION__ >= 199901L -# ifndef STDC99 -# define STDC99 -# endif -# endif +#ifndef STDC +#define STDC +#endif +#if __STDC_VERSION__ >= 199901L +#ifndef STDC99 +#define STDC99 +#endif +#endif #endif #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) -# define STDC +#define STDC #endif #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) -# define STDC +#define STDC #endif #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) -# define STDC +#define STDC #endif #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) -# define STDC +#define STDC #endif -#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ -# define STDC +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +#define STDC #endif #ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const /* note: need a more gentle solution here */ -# endif +#ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +#define const /* note: need a more gentle solution here */ +#endif #endif #if defined(ZLIB_CONST) && !defined(z_const) -# define z_const const +#define z_const const #else -# define z_const +#define z_const #endif #ifdef Z_SOLO - typedef unsigned long z_size_t; +typedef unsigned long z_size_t; +#else +#define z_longlong long long +#if defined(NO_SIZE_T) +typedef unsigned NO_SIZE_T z_size_t; +#elif defined(STDC) +#include <stddef.h> +typedef size_t z_size_t; #else -# define z_longlong long long -# if defined(NO_SIZE_T) - typedef unsigned NO_SIZE_T z_size_t; -# elif defined(STDC) -# include <stddef.h> - typedef size_t z_size_t; -# else - typedef unsigned long z_size_t; -# endif -# undef z_longlong +typedef unsigned long z_size_t; +#endif +#undef z_longlong #endif /* Maximum value for memLevel in deflateInit2 */ #ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif +#ifdef MAXSEG_64K +#define MAX_MEM_LEVEL 8 +#else +#define MAX_MEM_LEVEL 9 +#endif #endif /* Maximum value for windowBits in deflateInit2 and inflateInit2. @@ -267,7 +267,7 @@ * gzip.) */ #ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ +#define MAX_WBITS 15 /* 32K LZ77 window */ #endif /* The memory requirements for deflate are (in bytes): @@ -283,22 +283,22 @@ for small objects. */ - /* Type declarations */ +/* Type declarations */ #ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif +#ifdef STDC +#define OF(args) args +#else +#define OF(args) () +#endif #endif #ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +#define Z_ARG(args) args +#else +#define Z_ARG(args) () +#endif #endif /* The following definitions for FAR are needed only for MSDOS mixed @@ -308,153 +308,152 @@ * just define FAR to be empty. */ #ifdef SYS16BIT -# if defined(M_I86SM) || defined(M_I86MM) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -# endif -# if (defined(__SMALL__) || defined(__MEDIUM__)) - /* Turbo C small or medium model */ -# define SMALL_MEDIUM -# ifdef __BORLANDC__ -# define FAR _far -# else -# define FAR far -# endif -# endif +#if defined(M_I86SM) || defined(M_I86MM) +/* MSC small or medium model */ +#define SMALL_MEDIUM +#ifdef _MSC_VER +#define FAR _far +#else +#define FAR far +#endif +#endif +#if (defined(__SMALL__) || defined(__MEDIUM__)) +/* Turbo C small or medium model */ +#define SMALL_MEDIUM +#ifdef __BORLANDC__ +#define FAR _far +#else +#define FAR far +#endif +#endif #endif #if defined(WINDOWS) || defined(WIN32) - /* If building or using zlib as a DLL, define ZLIB_DLL. - * This is not mandatory, but it offers a little performance increase. - */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -# endif -# endif /* ZLIB_DLL */ - /* If building or using zlib with the WINAPI/WINAPIV calling convention, - * define ZLIB_WINAPI. - * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. - */ -# ifdef ZLIB_WINAPI -# ifdef FAR -# undef FAR -# endif -# include <windows.h> - /* No need for _export, use ZLIB.DEF instead. */ - /* For complete Windows compatibility, use WINAPI, not __stdcall. */ -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR CDECL -# endif -# endif -#endif - -#if defined (__BEOS__) -# ifdef ZLIB_DLL -# ifdef ZLIB_INTERNAL -# define ZEXPORT __declspec(dllexport) -# define ZEXPORTVA __declspec(dllexport) -# else -# define ZEXPORT __declspec(dllimport) -# define ZEXPORTVA __declspec(dllimport) -# endif -# endif -#endif - - -#if defined (__hCore__) -# ifdef ZLIB_DLL -# ifdef ZLIB_INTERNAL -# define ZEXPORT -# define ZEXPORTVA -# else -# define ZEXPORT -# define ZEXPORTVA -# endif -# endif +/* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +#ifdef ZLIB_DLL +#if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +#ifdef ZLIB_INTERNAL +#define ZEXTERN extern __declspec(dllexport) +#else +#define ZEXTERN extern __declspec(dllimport) +#endif +#endif +#endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +#ifdef ZLIB_WINAPI +#ifdef FAR +#undef FAR +#endif +#include <windows.h> +/* No need for _export, use ZLIB.DEF instead. */ +/* For complete Windows compatibility, use WINAPI, not __stdcall. */ +#define ZEXPORT WINAPI +#ifdef WIN32 +#define ZEXPORTVA WINAPIV +#else +#define ZEXPORTVA FAR CDECL +#endif +#endif +#endif + +#if defined(__BEOS__) +#ifdef ZLIB_DLL +#ifdef ZLIB_INTERNAL +#define ZEXPORT __declspec(dllexport) +#define ZEXPORTVA __declspec(dllexport) +#else +#define ZEXPORT __declspec(dllimport) +#define ZEXPORTVA __declspec(dllimport) +#endif +#endif +#endif + +#if defined(__HCORE__) +#ifdef ZLIB_DLL +#ifdef ZLIB_INTERNAL +#define ZEXPORT +#define ZEXPORTVA +#else +#define ZEXPORT +#define ZEXPORTVA +#endif +#endif #endif #ifndef ZEXTERN -# define ZEXTERN extern +#define ZEXTERN extern #endif #ifndef ZEXPORT -# define ZEXPORT +#define ZEXPORT #endif #ifndef ZEXPORTVA -# define ZEXPORTVA +#define ZEXPORTVA #endif #ifndef FAR -# define FAR +#define FAR #endif #if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ +typedef unsigned char Byte; /* 8 bits */ #endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ #ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR +/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +#define Bytef Byte FAR #else - typedef Byte FAR Bytef; +typedef Byte FAR Bytef; #endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; typedef uLong FAR uLongf; #ifdef STDC - typedef void const *voidpc; - typedef void FAR *voidpf; - typedef void *voidp; +typedef void const *voidpc; +typedef void FAR *voidpf; +typedef void *voidp; #else - typedef Byte const *voidpc; - typedef Byte FAR *voidpf; - typedef Byte *voidp; +typedef Byte const *voidpc; +typedef Byte FAR *voidpf; +typedef Byte *voidp; #endif typedef unsigned long z_crc_t; #if defined(__APPLE__) /* avoid unistd.h on Win32 */ -#if 1 /* was set to #if 1 by ./configure */ -# define Z_HAVE_UNISTD_H +#if 1 /* was set to #if 1 by ./configure */ +#define Z_HAVE_UNISTD_H #endif #endif /* defined(__APPLE__) */ -#if 1 /* was set to #if 1 by ./configure */ -# define Z_HAVE_STDARG_H +#if 1 /* was set to #if 1 by ./configure */ +#define Z_HAVE_STDARG_H #endif #ifdef STDC -# ifndef Z_SOLO -# include <sys/types.h> /* for off_t */ -# endif +#ifndef Z_SOLO +#include <sys/types.h> /* for off_t */ +#endif #endif #if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifndef Z_SOLO -# include <stdarg.h> /* for va_list */ -# endif +#ifndef Z_SOLO +#include <stdarg.h> /* for va_list */ +#endif #endif #ifdef _WIN32 -# ifndef Z_SOLO -# include <stddef.h> /* for wchar_t */ -# endif +#ifndef Z_SOLO +#include <stddef.h> /* for wchar_t */ +#endif #endif /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and @@ -464,74 +463,74 @@ typedef unsigned long z_crc_t; * equivalently requesting no 64-bit operations */ #if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 -# undef _LARGEFILE64_SOURCE +#undef _LARGEFILE64_SOURCE #endif #if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) -# define Z_HAVE_UNISTD_H +#define Z_HAVE_UNISTD_H #endif #ifndef Z_SOLO -# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) -# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ -# ifdef VMS -# include <unixio.h> /* for off_t */ -# endif -# if !defined(z_off_t) && !defined(__APPLE__) -# define z_off_t off_t -# endif -# endif +#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) +#include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ +#ifdef VMS +#include <unixio.h> /* for off_t */ +#endif +#if !defined(z_off_t) && !defined(__APPLE__) +#define z_off_t off_t +#endif +#endif #endif -#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 -# define Z_LFS64 +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE - 0 +#define Z_LFS64 #endif #if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) -# define Z_LARGE64 +#define Z_LARGE64 #endif -#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) -# define Z_WANT64 +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS - 0 == 64 && \ + defined(Z_LFS64) +#define Z_WANT64 #endif #if !defined(SEEK_SET) && !defined(Z_SOLO) -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#define SEEK_SET 0 /* Seek from beginning of file. */ +#define SEEK_CUR 1 /* Seek from current position. */ +#define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ #endif #ifndef z_off_t -# define z_off_t long +#define z_off_t long #endif #if !defined(_WIN32) && defined(Z_LARGE64) -# define z_off64_t off64_t +#define z_off64_t off64_t #elif defined(__APPLE__) -# define z_off64_t off_t +#define z_off64_t off_t #else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) -# define z_off64_t __int64 -# else -# define z_off64_t z_off_t -# endif +#if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +#define z_off64_t __int64 +#else +#define z_off64_t z_off_t +#endif #endif /* MVS linker does not support external names larger than 8 bytes */ #if defined(__MVS__) - #pragma map(deflateInit_,"DEIN") - #pragma map(deflateInit2_,"DEIN2") - #pragma map(deflateEnd,"DEEND") - #pragma map(deflateBound,"DEBND") - #pragma map(inflateInit_,"ININ") - #pragma map(inflateInit2_,"ININ2") - #pragma map(inflateEnd,"INEND") - #pragma map(inflateSync,"INSY") - #pragma map(inflateSetDictionary,"INSEDI") - #pragma map(compressBound,"CMBND") - #pragma map(inflate_table,"INTABL") - #pragma map(inflate_fast,"INFA") - #pragma map(inflate_copyright,"INCOPY") +#pragma map(deflateInit_, "DEIN") +#pragma map(deflateInit2_, "DEIN2") +#pragma map(deflateEnd, "DEEND") +#pragma map(deflateBound, "DEBND") +#pragma map(inflateInit_, "ININ") +#pragma map(inflateInit2_, "ININ2") +#pragma map(inflateEnd, "INEND") +#pragma map(inflateSync, "INSY") +#pragma map(inflateSetDictionary, "INSEDI") +#pragma map(compressBound, "CMBND") +#pragma map(inflate_table, "INTABL") +#pragma map(inflate_fast, "INFA") +#pragma map(inflate_copyright, "INCOPY") #endif #endif /* ZCONF_H */ - diff --git a/Public/SDK/ZipKit/zlib.hpp b/Public/SDK/ZipKit/zlib.hpp index 3b576f67..540ab3e8 100644 --- a/Public/SDK/ZipKit/zlib.hpp +++ b/Public/SDK/ZipKit/zlib.hpp @@ -82,30 +82,30 @@ extern "C" { */ typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size); -typedef void (*free_func)(voidpf opaque, voidpf address); +typedef void (*free_func)(voidpf opaque, voidpf address); struct internal_state; typedef struct z_stream_s { - z_const Bytef *next_in; /* next input byte */ - uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total number of input bytes read so far */ + z_const Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total number of input bytes read so far */ - Bytef *next_out; /* next output byte will go here */ - uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total number of bytes output so far */ + Bytef *next_out; /* next output byte will go here */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total number of bytes output so far */ - z_const char *msg; /* last error message, NULL if no error */ - struct internal_state FAR *state; /* not visible by applications */ + z_const char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ - alloc_func zalloc; /* used to allocate the internal state */ - free_func zfree; /* used to free the internal state */ - voidpf opaque; /* private data object passed to zalloc and zfree */ + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ - int data_type; /* best guess about the data type: binary or text - for deflate, or the decoding state for inflate */ - uLong adler; /* Adler-32 or CRC-32 value of the uncompressed data */ - uLong reserved; /* reserved for future use */ + int data_type; /* best guess about the data type: binary or text + for deflate, or the decoding state for inflate */ + uLong adler; /* Adler-32 or CRC-32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ } z_stream; typedef z_stream FAR *z_streamp; @@ -115,20 +115,20 @@ typedef z_stream FAR *z_streamp; for more details on the meanings of these fields. */ typedef struct gz_header_s { - int text; /* true if compressed data believed to be text */ - uLong time; /* modification time */ - int xflags; /* extra flags (not used when writing a gzip file) */ - int os; /* operating system */ - Bytef *extra; /* pointer to extra field or Z_NULL if none */ - uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ - uInt extra_max; /* space at extra (only when reading header) */ - Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ - uInt name_max; /* space at name (only when reading header) */ - Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ - uInt comm_max; /* space at comment (only when reading header) */ - int hcrc; /* true if there was or will be a header crc */ - int done; /* true when done reading gzip header (not used - when writing a gzip file) */ + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ } gz_header; typedef gz_header FAR *gz_headerp; @@ -166,61 +166,60 @@ typedef gz_header FAR *gz_headerp; if the decompressor wants to decompress everything in a single step). */ - /* constants */ +/* constants */ -#define Z_NO_FLUSH 0 +#define Z_NO_FLUSH 0 #define Z_PARTIAL_FLUSH 1 -#define Z_SYNC_FLUSH 2 -#define Z_FULL_FLUSH 3 -#define Z_FINISH 4 -#define Z_BLOCK 5 -#define Z_TREES 6 +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +#define Z_TREES 6 /* Allowed flush values; see deflate() and inflate() below for details */ -#define Z_OK 0 -#define Z_STREAM_END 1 -#define Z_NEED_DICT 2 -#define Z_ERRNO (-1) +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) #define Z_STREAM_ERROR (-2) -#define Z_DATA_ERROR (-3) -#define Z_MEM_ERROR (-4) -#define Z_BUF_ERROR (-5) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) #define Z_VERSION_ERROR (-6) /* Return codes for the compression/decompression functions. Negative values * are errors, positive values are used for special but normal events. */ -#define Z_NO_COMPRESSION 0 -#define Z_BEST_SPEED 1 -#define Z_BEST_COMPRESSION 9 -#define Z_DEFAULT_COMPRESSION (-1) +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) /* compression levels */ -#define Z_FILTERED 1 -#define Z_HUFFMAN_ONLY 2 -#define Z_RLE 3 -#define Z_FIXED 4 -#define Z_DEFAULT_STRATEGY 0 +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 /* compression strategy; see deflateInit2() below for details */ -#define Z_BINARY 0 -#define Z_TEXT 1 -#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ -#define Z_UNKNOWN 2 +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 /* Possible values of the data_type field for deflate() */ -#define Z_DEFLATED 8 +#define Z_DEFLATED 8 /* The deflate compression method (the only one supported in this version) */ -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ #define zlib_version zlibVersion() /* for compatibility with versions < 1.0.2 */ +/* basic functions */ - /* basic functions */ - -ZEXTERN const char * ZEXPORT zlibVersion(void); +ZEXTERN const char *ZEXPORT zlibVersion(void); /* The application can compare zlibVersion and ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check @@ -249,7 +248,6 @@ ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level); this will be done by deflate(). */ - ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush); /* deflate compresses as much data as possible, and stops when the input @@ -362,7 +360,6 @@ ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush); continue compressing. */ - ZEXTERN int ZEXPORT deflateEnd(z_streamp strm); /* All dynamically allocated data structures for this stream are freed. @@ -376,7 +373,6 @@ ZEXTERN int ZEXPORT deflateEnd(z_streamp strm); deallocated). */ - /* ZEXTERN int ZEXPORT inflateInit(z_streamp strm); @@ -400,7 +396,6 @@ ZEXTERN int ZEXPORT inflateInit(z_streamp strm); that is deferred until inflate() is called. */ - ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush); /* inflate decompresses as much data as possible, and stops when the input @@ -520,7 +515,6 @@ ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush); recovery of the data is to be attempted. */ - ZEXTERN int ZEXPORT inflateEnd(z_streamp strm); /* All dynamically allocated data structures for this stream are freed. @@ -531,8 +525,7 @@ ZEXTERN int ZEXPORT inflateEnd(z_streamp strm); was inconsistent. */ - - /* Advanced functions */ +/* Advanced functions */ /* The following functions are needed only in some special applications. @@ -613,7 +606,7 @@ ZEXTERN int ZEXPORT deflateInit2(z_streamp strm, ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, - uInt dictLength); + uInt dictLength); /* Initializes the compression dictionary from the given byte sequence without producing any compressed output. When using the zlib format, this @@ -655,9 +648,8 @@ ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm, not perform any compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm, - Bytef *dictionary, - uInt *dictLength); +ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength); /* Returns the sliding dictionary being maintained by deflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -677,8 +669,7 @@ ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm, stream state is inconsistent. */ -ZEXTERN int ZEXPORT deflateCopy(z_streamp dest, - z_streamp source); +ZEXTERN int ZEXPORT deflateCopy(z_streamp dest, z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -706,9 +697,7 @@ ZEXTERN int ZEXPORT deflateReset(z_streamp strm); stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT deflateParams(z_streamp strm, - int level, - int strategy); +ZEXTERN int ZEXPORT deflateParams(z_streamp strm, int level, int strategy); /* Dynamically update the compression level and compression strategy. The interpretation of level and strategy is as in deflateInit2(). This can be @@ -744,11 +733,8 @@ ZEXTERN int ZEXPORT deflateParams(z_streamp strm, retried with more output space. */ -ZEXTERN int ZEXPORT deflateTune(z_streamp strm, - int good_length, - int max_lazy, - int nice_length, - int max_chain); +ZEXTERN int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, + int nice_length, int max_chain); /* Fine tune deflate's internal compression parameters. This should only be used by someone who understands the algorithm used by zlib's deflate for @@ -761,8 +747,7 @@ ZEXTERN int ZEXPORT deflateTune(z_streamp strm, returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. */ -ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, - uLong sourceLen); +ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen); /* deflateBound() returns an upper bound on the compressed size after deflation of sourceLen bytes. It must be called after deflateInit() or @@ -776,8 +761,7 @@ ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, than Z_FINISH or Z_NO_FLUSH are used. */ -ZEXTERN int ZEXPORT deflatePending(z_streamp strm, - unsigned *pending, +ZEXTERN int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits); /* deflatePending() returns the number of bytes and bits of output that have @@ -791,9 +775,7 @@ ZEXTERN int ZEXPORT deflatePending(z_streamp strm, stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, - int bits, - int value); +ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, int bits, int value); /* deflatePrime() inserts bits in the deflate output stream. The intent is that this function is used to start off the deflate output with the bits @@ -808,8 +790,7 @@ ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, source stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm, - gz_headerp head); +ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head); /* deflateSetHeader() provides gzip header information for when a gzip stream is requested by deflateInit2(). deflateSetHeader() may be called @@ -890,7 +871,7 @@ ZEXTERN int ZEXPORT inflateInit2(z_streamp strm, ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, - uInt dictLength); + uInt dictLength); /* Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of inflate, @@ -911,9 +892,8 @@ ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm, inflate(). */ -ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm, - Bytef *dictionary, - uInt *dictLength); +ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength); /* Returns the sliding dictionary being maintained by inflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -945,8 +925,7 @@ ZEXTERN int ZEXPORT inflateSync(z_streamp strm); input each time, until success or end of the input data. */ -ZEXTERN int ZEXPORT inflateCopy(z_streamp dest, - z_streamp source); +ZEXTERN int ZEXPORT inflateCopy(z_streamp dest, z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -972,8 +951,7 @@ ZEXTERN int ZEXPORT inflateReset(z_streamp strm); stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT inflateReset2(z_streamp strm, - int windowBits); +ZEXTERN int ZEXPORT inflateReset2(z_streamp strm, int windowBits); /* This function is the same as inflateReset, but it also permits changing the wrap and window size requests. The windowBits parameter is interpreted @@ -986,9 +964,7 @@ ZEXTERN int ZEXPORT inflateReset2(z_streamp strm, the windowBits parameter is invalid. */ -ZEXTERN int ZEXPORT inflatePrime(z_streamp strm, - int bits, - int value); +ZEXTERN int ZEXPORT inflatePrime(z_streamp strm, int bits, int value); /* This function inserts bits in the inflate input stream. The intent is that this function is used to start inflating at a bit position in the @@ -1035,8 +1011,7 @@ ZEXTERN long ZEXPORT inflateMark(z_streamp strm); source stream state was inconsistent. */ -ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm, - gz_headerp head); +ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head); /* inflateGetHeader() requests that gzip header information be stored in the provided gz_header structure. inflateGetHeader() may be called after @@ -1097,12 +1072,10 @@ ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits, the version of the header file. */ -typedef unsigned (*in_func)(void FAR *, - z_const unsigned char FAR * FAR *); +typedef unsigned (*in_func)(void FAR *, z_const unsigned char FAR *FAR *); typedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned); -ZEXTERN int ZEXPORT inflateBack(z_streamp strm, - in_func in, void FAR *in_desc, +ZEXTERN int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc); /* inflateBack() does a raw inflate with a single call using a call-back @@ -1222,7 +1195,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags(void); #ifndef Z_SOLO - /* utility functions */ +/* utility functions */ /* The following utility functions are implemented on top of the basic @@ -1232,8 +1205,8 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags(void); you need special options. */ -ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen); +ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong sourceLen); /* Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1247,9 +1220,8 @@ ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen, buffer. */ -ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level); +ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong sourceLen, int level); /* Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in deflateInit. sourceLen is the byte @@ -1270,7 +1242,7 @@ ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen); compress() or compress2() call to allocate the destination buffer. */ -ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, +ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); /* Decompresses the source buffer into the destination buffer. sourceLen is @@ -1288,7 +1260,7 @@ ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, buffer with the uncompressed data up to that point. */ -ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, +ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, uLong *sourceLen); /* Same as uncompress, except that sourceLen is a pointer, where the @@ -1296,7 +1268,7 @@ ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, source bytes consumed. */ - /* gzip file access functions */ +/* gzip file access functions */ /* This library supports reading and writing files in gzip (.gz) format with @@ -1305,7 +1277,7 @@ ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, wrapper, documented in RFC 1952, wrapped around a deflate stream. */ -typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ +typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ /* ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode); @@ -1457,8 +1429,8 @@ ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len); returns the number of uncompressed bytes written or 0 in case of error. */ -ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, - z_size_t nitems, gzFile file); +ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems, + gzFile file); /* Compress and write nitems items of size size from buf to file, duplicating the interface of stdio's fwrite(), with size_t request and return types. If @@ -1494,7 +1466,7 @@ ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s); gzputs returns the number of characters written, or -1 in case of error. */ -ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len); +ZEXTERN char *ZEXPORT gzgets(gzFile file, char *buf, int len); /* Read and decompress bytes from file into buf, until len-1 characters are read, or until a newline character is read and transferred to buf, or an @@ -1570,7 +1542,7 @@ ZEXTERN z_off_t ZEXPORT gzseek(gzFile file, would be before the current position. */ -ZEXTERN int ZEXPORT gzrewind(gzFile file); +ZEXTERN int ZEXPORT gzrewind(gzFile file); /* Rewind file. This function is supported only for reading. @@ -1634,7 +1606,7 @@ ZEXTERN int ZEXPORT gzdirect(gzFile file); gzip file reading and decompression, which may not be desired.) */ -ZEXTERN int ZEXPORT gzclose(gzFile file); +ZEXTERN int ZEXPORT gzclose(gzFile file); /* Flush all pending output for file, if necessary, close file and deallocate the (de)compression state. Note that once file is closed, you @@ -1659,7 +1631,7 @@ ZEXTERN int ZEXPORT gzclose_w(gzFile file); zlib library. */ -ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum); +ZEXTERN const char *ZEXPORT gzerror(gzFile file, int *errnum); /* Return the error message for the last error which occurred on file. errnum is set to zlib error number. If an error occurred in the file system @@ -1684,7 +1656,7 @@ ZEXTERN void ZEXPORT gzclearerr(gzFile file); #endif /* !Z_SOLO */ - /* checksum functions */ +/* checksum functions */ /* These functions are not related to compression but are exported @@ -1712,8 +1684,7 @@ ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len); if (adler != original_adler) error(); */ -ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, - z_size_t len); +ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len); /* Same as adler32(), but with a size_t length. */ @@ -1748,8 +1719,7 @@ ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len); if (crc != original_crc) error(); */ -ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf, - z_size_t len); +ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf, z_size_t len); /* Same as crc32(), but with a size_t length. */ @@ -1778,54 +1748,49 @@ ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op); crc32_combine() if the generated op is used more than once. */ - - /* various hacks, don't look :) */ +/* various hacks, don't look :) */ /* deflateInit and inflateInit are macros to allow checking the zlib version * and the compiler's view of z_stream: */ -ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level, - const char *version, int stream_size); -ZEXTERN int ZEXPORT inflateInit_(z_streamp strm, - const char *version, int stream_size); -ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size); -ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, +ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, + int stream_size); +ZEXTERN int ZEXPORT inflateInit_(z_streamp strm, const char *version, + int stream_size); +ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + int windowBits, int memLevel, int strategy, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size); ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, unsigned char FAR *window, - const char *version, - int stream_size); + const char *version, int stream_size); #ifdef Z_PREFIX_SET -# define z_deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) -# define z_inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) -# define z_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) -# define z_inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ - (int)sizeof(z_stream)) -# define z_inflateBackInit(strm, windowBits, window) \ - inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, (int)sizeof(z_stream)) +#define z_deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) +#define z_inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) +#define z_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm), (level), (method), (windowBits), (memLevel), \ + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) +#define z_inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, (int)sizeof(z_stream)) +#define z_inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), ZLIB_VERSION, \ + (int)sizeof(z_stream)) #else -# define deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) -# define inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) -# define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) -# define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ - (int)sizeof(z_stream)) -# define inflateBackInit(strm, windowBits, window) \ - inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, (int)sizeof(z_stream)) +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm), (level), (method), (windowBits), (memLevel), \ + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, (int)sizeof(z_stream)) +#define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), ZLIB_VERSION, \ + (int)sizeof(z_stream)) #endif #ifndef Z_SOLO @@ -1838,18 +1803,18 @@ ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, * only be used by the gzgetc() macro. You have been warned. */ struct gzFile_s { - unsigned have; - unsigned char *next; - z_off64_t pos; + unsigned have; + unsigned char *next; + z_off64_t pos; }; -ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */ +ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */ #ifdef Z_PREFIX_SET -# undef z_gzgetc -# define z_gzgetc(g) \ - ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) +#undef z_gzgetc +#define z_gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) #else -# define gzgetc(g) \ - ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) +#define gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) #endif /* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or @@ -1859,79 +1824,76 @@ ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */ * without large file support, _LFS64_LARGEFILE must also be true */ #ifdef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); - ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); - ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); - ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); - ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t); - ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t); - ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t); +ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); +ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); +ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); +ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); +ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t); +ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t); +ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t); #endif #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) -# ifdef Z_PREFIX_SET -# define z_gzopen z_gzopen64 -# define z_gzseek z_gzseek64 -# define z_gztell z_gztell64 -# define z_gzoffset z_gzoffset64 -# define z_adler32_combine z_adler32_combine64 -# define z_crc32_combine z_crc32_combine64 -# define z_crc32_combine_gen z_crc32_combine_gen64 -# else -# define gzopen gzopen64 -# define gzseek gzseek64 -# define gztell gztell64 -# define gzoffset gzoffset64 -# define adler32_combine adler32_combine64 -# define crc32_combine crc32_combine64 -# define crc32_combine_gen crc32_combine_gen64 -# endif -# ifndef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); - ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int); - ZEXTERN z_off_t ZEXPORT gztell64(gzFile); - ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile); - ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); -# endif +#ifdef Z_PREFIX_SET +#define z_gzopen z_gzopen64 +#define z_gzseek z_gzseek64 +#define z_gztell z_gztell64 +#define z_gzoffset z_gzoffset64 +#define z_adler32_combine z_adler32_combine64 +#define z_crc32_combine z_crc32_combine64 +#define z_crc32_combine_gen z_crc32_combine_gen64 +#else +#define gzopen gzopen64 +#define gzseek gzseek64 +#define gztell gztell64 +#define gzoffset gzoffset64 +#define adler32_combine adler32_combine64 +#define crc32_combine crc32_combine64 +#define crc32_combine_gen crc32_combine_gen64 +#endif +#ifndef Z_LARGE64 +ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); +ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int); +ZEXTERN z_off_t ZEXPORT gztell64(gzFile); +ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile); +ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); +ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); +ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); +#endif #else - ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *); - ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int); - ZEXTERN z_off_t ZEXPORT gztell(gzFile); - ZEXTERN z_off_t ZEXPORT gzoffset(gzFile); - ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); +ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *); +ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int); +ZEXTERN z_off_t ZEXPORT gztell(gzFile); +ZEXTERN z_off_t ZEXPORT gzoffset(gzFile); +ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); +ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); +ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); #endif #else /* Z_SOLO */ - ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); - ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); +ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); +ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); +ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); #endif /* !Z_SOLO */ /* undocumented functions */ -ZEXTERN const char * ZEXPORT zError(int); -ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp); -ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void); -ZEXTERN int ZEXPORT inflateUndermine(z_streamp, int); -ZEXTERN int ZEXPORT inflateValidate(z_streamp, int); -ZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp); -ZEXTERN int ZEXPORT inflateResetKeep(z_streamp); -ZEXTERN int ZEXPORT deflateResetKeep(z_streamp); +ZEXTERN const char *ZEXPORT zError(int); +ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp); +ZEXTERN const z_crc_t FAR *ZEXPORT get_crc_table(void); +ZEXTERN int ZEXPORT inflateUndermine(z_streamp, int); +ZEXTERN int ZEXPORT inflateValidate(z_streamp, int); +ZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp); +ZEXTERN int ZEXPORT inflateResetKeep(z_streamp); +ZEXTERN int ZEXPORT deflateResetKeep(z_streamp); #if defined(_WIN32) && !defined(Z_SOLO) -ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path, - const char *mode); +ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode); #endif #if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifndef Z_SOLO -ZEXTERN int ZEXPORTVA gzvprintf(gzFile file, - const char *format, - va_list va); -# endif +#ifndef Z_SOLO +ZEXTERN int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va); +#endif #endif #ifdef __cplusplus @@ -1939,5 +1901,3 @@ ZEXTERN int ZEXPORTVA gzvprintf(gzFile file, #endif #endif /* ZLIB_H */ - - diff --git a/SPECIFICATION.TXT b/SPECIFICATION.TXT index f49a4285..504e1278 100644 --- a/SPECIFICATION.TXT +++ b/SPECIFICATION.TXT @@ -7,18 +7,17 @@ - Language: C++/C/Assembly (AMD64, X64000, X86S, ARM64) =================================== -1: The hCore Microkernel +1: The HCore Microkernel =================================== -hCore mounts NewFS by default, -a journal filesystem meant for GUI use. +HCore mounts NewFS by default, a journal filesystem meant for GUI use. It makes use of a concept named 'Fork' It contains data about a specific 'Catalog' Programs are load using the PEF. PEF is a multiplatform container for executables/shared libraries. Dwarf is used for debugging. -hCore has SMP in it's core with a preemptive multi-threaded scheduler. +HCore has SMP in it's core with a preemptive multi-threaded scheduler. It also supports dynamic loading of symbols and has a rich driver system. ==================================== diff --git a/TODO_LIST.TXT b/TODO_LIST.TXT index a7c14ba5..14c6a6d5 100644 --- a/TODO_LIST.TXT +++ b/TODO_LIST.TXT @@ -3,5 +3,7 @@ - We also need a system library for the OS. [ X ] - We need a bootloader for AMD64 [ X ] - Implement Boot Services [ X ] - - Load Handover and kernel into memory [ ] + - Design Handover [ X ] + - Load kernel into memory [ ] - Jump to kernel [ ] +- Add Native Subsystem and GUI [ ] |
