diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-07-28 16:11:46 +0000 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-07-28 16:11:46 +0000 |
| commit | c4023005e029ae092dad2689564c490580dd5c28 (patch) | |
| tree | 3080ba07a6b552bf3d7591574cf69b2a3c8fd0fd /Kernel | |
| parent | 8c8822fff78f9ff9cd640271da9b3634c4c2f97f (diff) | |
| parent | 4db57a2d646b1538783a0675b38bada7a0f903ae (diff) | |
Merged in MHR-36 (pull request #17)
MHR-36
Diffstat (limited to 'Kernel')
251 files changed, 2977 insertions, 1929 deletions
diff --git a/Kernel/ArchKit/ArchKit.hpp b/Kernel/ArchKit/ArchKit.hpp index 622d7219..a4d272ec 100644 --- a/Kernel/ArchKit/ArchKit.hpp +++ b/Kernel/ArchKit/ArchKit.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -10,12 +10,14 @@ #include <NewKit/Defines.hpp> #include <NewKit/Function.hpp> +#include <FirmwareKit/Handover.hxx> + #ifdef __NEWOS_AMD64__ -#include <HALKit/AMD64/HalPageAlloc.hpp> +#include <HALKit/AMD64/HalPageAlloc.hxx> #include <HALKit/AMD64/Hypervisor.hpp> -#include <HALKit/AMD64/Processor.hpp> -#elif defined(__NEWOS_PPC__) -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> +#elif defined(__NEWOS_POWER64__) +#include <HALKit/POWER/Processor.hxx> #elif defined(__NEWOS_ARM64__) #include <HALKit/ARM64/Processor.hxx> #else @@ -24,7 +26,7 @@ namespace Kernel { - constexpr static inline SSizeT rt_hash_seed(const char* seed, int mul) + inline SSizeT rt_hash_seed(const char* seed, int mul) { SSizeT hash = 0; @@ -41,7 +43,7 @@ namespace Kernel /// @param base the base address. /// @param reg the register. /// @param value the write to write on it. - inline void ke_dma_write(UInt32 base, UInt32 reg, UInt32 value) noexcept + inline Void ke_dma_write(UInt32 base, UInt32 reg, UInt32 value) noexcept { *(volatile UInt32*)((UInt64)base + reg) = value; } @@ -58,18 +60,19 @@ namespace Kernel /// @brief Print a region of memory. /// @param start /// @param length - inline void ke_print_raw_memory(const void* start, Size length) + inline Void ke_print_raw_memory(const void* start, Size length) { const UInt8* ptr = (const UInt8*)start; + for (Size i = 0; i < length; i++) { if (i % 16 == 0) { - kcout << hex_number((UIntPtr)ptr + i); + kcout.HexNumber((UIntPtr)ptr + i); } else { - kcout << hex_number(ptr[i]); + kcout.HexNumber(ptr[i]); } kcout << " "; @@ -86,19 +89,17 @@ typedef Kernel::Void (*rt_syscall_proc)(Kernel::VoidPtr); struct RTSyscallInfoHdr final { Kernel::Int64 fHash; - Kernel::Bool fHooked; + Kernel::Bool fHooked; rt_syscall_proc fProc; }; inline Kernel::Array<RTSyscallInfoHdr, - kKernelMaxSystemCalls> + kKernelMaxSystemCalls> kSyscalls; inline Kernel::Array<RTSyscallInfoHdr, - kKernelMaxSystemCalls> + kKernelMaxSystemCalls> kKerncalls; EXTERN_C Kernel::HAL::StackFramePtr rt_get_current_context(); EXTERN_C Kernel::Void rt_do_context_switch(Kernel::HAL::StackFramePtr stackFrame); - -#include <FirmwareKit/Handover.hxx> diff --git a/Kernel/ArchKit/compile_flags.txt b/Kernel/ArchKit/compile_flags.txt index a3cab89d..c15efc77 100644 --- a/Kernel/ArchKit/compile_flags.txt +++ b/Kernel/ArchKit/compile_flags.txt @@ -5,3 +5,4 @@ -I../ -I$(HOME)/ -D__NEWOS_AMD64__ +-D__ED__ diff --git a/Kernel/CFKit/GUIDWizard.hpp b/Kernel/CFKit/GUIDWizard.hpp index 6fd747e9..609b0d46 100644 --- a/Kernel/CFKit/GUIDWizard.hpp +++ b/Kernel/CFKit/GUIDWizard.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -11,12 +11,12 @@ #include <NewKit/ArrayList.hpp> #include <NewKit/Defines.hpp> #include <NewKit/ErrorOr.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> #include <NewKit/Stream.hpp> #include <NewKit/String.hpp> namespace Kernel::XRN::Version1 { - Ref<GUIDSequence*> make_sequence(const ArrayList<UShort>& seq); - ErrorOr<Ref<Kernel::StringView>> try_guid_to_string(Ref<GUIDSequence*>& guid); + Ref<GUIDSequence*> cf_make_sequence(const ArrayList<UInt32>& seq); + ErrorOr<Ref<Kernel::StringView>> cf_try_guid_to_string(Ref<GUIDSequence*>& guid); } // namespace Kernel::XRN::Version1 diff --git a/Kernel/CFKit/GUIDWrapper.hpp b/Kernel/CFKit/GUIDWrapper.hpp index f8f08591..fe9e373b 100644 --- a/Kernel/CFKit/GUIDWrapper.hpp +++ b/Kernel/CFKit/GUIDWrapper.hpp @@ -1,13 +1,13 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #pragma once #include <NewKit/Defines.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> #include <NewKit/Stream.hpp> /* GUID for C++ Components */ diff --git a/Kernel/CFKit/LoaderUtils.hxx b/Kernel/CFKit/LoaderUtils.hxx new file mode 100644 index 00000000..3edacc67 --- /dev/null +++ b/Kernel/CFKit/LoaderUtils.hxx @@ -0,0 +1,54 @@ +#ifndef __CFKIT_LOADER_UTILS_HXX__ +#define __CFKIT_LOADER_UTILS_HXX__ + +#include <KernelKit/PE.hxx> +#include <KernelKit/MSDOS.hxx> + +namespace Kernel +{ + /// @brief Find the PE header inside the blob. + inline auto ldr_find_exec_header(DosHeaderPtr ptrDos) -> ExecHeaderPtr + { + if (!ptrDos) + return nullptr; + + if (ptrDos->eMagic[0] != kMagMz0) + return nullptr; + + if (ptrDos->eMagic[1] != kMagMz1) + return nullptr; + + return (ExecHeaderPtr)(VoidPtr)(&ptrDos->eLfanew + 1); + } + + /// @brief Find the PE optional header inside the blob. + inline auto ldr_find_opt_exec_header(DosHeaderPtr ptrDos) -> ExecOptionalHeaderPtr + { + if (!ptrDos) + return nullptr; + + auto exec = ldr_find_exec_header(ptrDos); + + if (!exec) + return nullptr; + + return (ExecOptionalHeaderPtr)(VoidPtr)(&exec->mCharacteristics + 1); + } + + /// @brief Find the PE header inside the blob. + /// @note overloaded function. + inline auto ldr_find_exec_header(const Char* ptrDos) -> ExecHeaderPtr + { + return ldr_find_exec_header((DosHeaderPtr)ptrDos); + } + + + /// @brief Find the PE header inside the blob. + /// @note overloaded function. + inline auto ldr_find_opt_exec_header(const Char* ptrDos) -> ExecOptionalHeaderPtr + { + return ldr_find_opt_exec_header((DosHeaderPtr)ptrDos); + } +} // namespace Kernel + +#endif // ifndef __CFKIT_LOADER_UTILS_HXX__ diff --git a/Kernel/CFKit/Property.hpp b/Kernel/CFKit/Property.hpp index f75e7f95..519f486e 100644 --- a/Kernel/CFKit/Property.hpp +++ b/Kernel/CFKit/Property.hpp @@ -1,17 +1,19 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#ifndef __INC_PLIST_HPP__ -#define __INC_PLIST_HPP__ +#ifndef __INC_PROPS_HPP__ +#define __INC_PROPS_HPP__ #include <NewKit/Array.hpp> #include <NewKit/Defines.hpp> #include <NewKit/Function.hpp> #include <NewKit/String.hpp> +#define cMaxPropLen 4096 + namespace Kernel { /// @brief handle to anything (number, ptr, string...) @@ -22,23 +24,24 @@ namespace Kernel class Property { public: - explicit Property(const StringView& sw); + Property() = default; virtual ~Property(); public: Property& operator=(const Property&) = default; Property(const Property&) = default; - bool StringEquals(StringView& name); - const PropertyId& GetPropertyById(); + bool StringEquals(StringView& name); + PropertyId& GetValue(); + StringView& GetKey(); private: - Ref<StringView> fName; - PropertyId fAction; + StringView fName{cMaxPropLen}; + PropertyId fAction{No}; }; template <SizeT N> using PropertyArray = Array<Property, N>; } // namespace Kernel -#endif // !__INC_PLIST_HPP__ +#endif // !__INC_PROPS_HPP__ diff --git a/Kernel/CFKit/URL.hpp b/Kernel/CFKit/URL.hpp index 049e1194..61c08d0f 100644 --- a/Kernel/CFKit/URL.hpp +++ b/Kernel/CFKit/URL.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -26,8 +26,8 @@ namespace Kernel Ref<StringView> fUrlView; }; - ErrorOr<StringView> url_extract_location(const char* url); - ErrorOr<StringView> url_extract_protocol(const char* url); + ErrorOr<StringView> url_extract_location(const Char* url); + ErrorOr<StringView> url_extract_protocol(const Char* url); } // namespace Kernel #endif /* ifndef _INC_URL_HPP_ */ diff --git a/Kernel/CRT/__mpcc_alloca.hxx b/Kernel/CRT/__mpcc_alloca.hxx index 19ebaaf8..02b31230 100644 --- a/Kernel/CRT/__mpcc_alloca.hxx +++ b/Kernel/CRT/__mpcc_alloca.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/CRT/__mpcc_defines.hxx b/Kernel/CRT/__mpcc_defines.hxx index 55bf7b2b..9dfe51af 100644 --- a/Kernel/CRT/__mpcc_defines.hxx +++ b/Kernel/CRT/__mpcc_defines.hxx @@ -1,11 +1,11 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#ifndef __MPCC_DEF__ -#define __MPCC_DEF__ +#ifndef __MPCC_DEFINES_HXX__ +#define __MPCC_DEFINES_HXX__ #ifndef __GNUC__ @@ -30,7 +30,7 @@ typedef char* caddr_t; #ifdef __GNUC__ #include <CRT/__mpcc_alloca.hxx> #define __mpcc_alloca(sz) __mpcc_alloca_gcc(sz) -#elif defined(__MPCC__) +#elif defined(__NDK__) #define __alloca(sz) __mpcc_alloca(sz) #endif @@ -95,4 +95,4 @@ typedef union double_cast { #endif // ifdef __STD_CXX__ -#endif /* __MPCC_DEF__ */ +#endif /* __MPCC_DEFINES_HXX__ */ diff --git a/Kernel/CRT/__mpcc_exception.hxx b/Kernel/CRT/__mpcc_exception.hxx index 846a1cde..c6e973f4 100644 --- a/Kernel/CRT/__mpcc_exception.hxx +++ b/Kernel/CRT/__mpcc_exception.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/CRT/__mpcc_malloc.hxx b/Kernel/CRT/__mpcc_malloc.hxx index 31fb631d..1d11f5b0 100644 --- a/Kernel/CRT/__mpcc_malloc.hxx +++ b/Kernel/CRT/__mpcc_malloc.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/CompilerKit/CompilerKit.hxx b/Kernel/CompilerKit/CompilerKit.hxx index 5d51118e..f8c0a0d3 100644 --- a/Kernel/CompilerKit/CompilerKit.hxx +++ b/Kernel/CompilerKit/CompilerKit.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/CompilerKit/Detail.hxx b/Kernel/CompilerKit/Detail.hxx index c51b84ab..700a794d 100644 --- a/Kernel/CompilerKit/Detail.hxx +++ b/Kernel/CompilerKit/Detail.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Docs/TODO-LIST.md b/Kernel/Docs/TODO-LIST.md index ed7b1cf9..62cc886c 100644 --- a/Kernel/Docs/TODO-LIST.md +++ b/Kernel/Docs/TODO-LIST.md @@ -13,11 +13,13 @@ - AHCI driver [ WiP ] - Context switch x87/SSE/AVX registers [ X ] - Framebuffer [ X ] -- AHCI support [ ] -- Make installer [ ] +- ATA support [ X ] +- Make installer [ X ] Status: -newosldr: Need to boot from EPM partition. +newosldr: Need to boot from EPM partition. [ X ] <br> -NewKernel: New Filesystem in progress. +NewKernel: New Filesystem is done. [ X ] + +**Refer to Jira!** diff --git a/Kernel/FSKit/Defines.hxx b/Kernel/FSKit/Defines.hxx index c70e86cc..f6ada2aa 100644 --- a/Kernel/FSKit/Defines.hxx +++ b/Kernel/FSKit/Defines.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/FSKit/FAT32.hxx b/Kernel/FSKit/FAT32.hxx index 4aa0fc2b..43c647cc 100644 --- a/Kernel/FSKit/FAT32.hxx +++ b/Kernel/FSKit/FAT32.hxx @@ -1,6 +1,6 @@ /* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
diff --git a/Kernel/FSKit/IndexableProperty.hxx b/Kernel/FSKit/IndexableProperty.hxx index d1001415..ecc6a436 100644 --- a/Kernel/FSKit/IndexableProperty.hxx +++ b/Kernel/FSKit/IndexableProperty.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -28,8 +28,12 @@ namespace Kernel { public: explicit IndexableProperty() - : Property(StringBuilder::Construct("\\Filesystem\\IsIndexable?").Leak().Leak()) + : Property() { + Kernel::StringView strProp(cMaxPropLen); + strProp += "\\Properties\\Indexable"; + + this->GetKey() = strProp; } ~IndexableProperty() override = default; diff --git a/Kernel/FSKit/NewFS.hxx b/Kernel/FSKit/NewFS.hxx index bcef3797..711bde0b 100644 --- a/Kernel/FSKit/NewFS.hxx +++ b/Kernel/FSKit/NewFS.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: NewFS.hxx Purpose: @@ -36,9 +36,6 @@ default. #define kNewFSIdent " NewFS" #define kNewFSPadLen (400) -/// @brief Partition GUID on EPM and GPT disks. -#define kNewFSUUID "@{DD997393-9CCE-4288-A8D5-C0FDE3908DBE}" - #define kNewFSVersionInteger (0x126) #define kNewFSVerionString "1.26" @@ -68,10 +65,14 @@ default. #define kNewFSCatalogKindDevice (9) #define kNewFSCatalogKindLock (10) +#define kNewFSCatalogKindRLE (11) + #define kNewFSSeparator '\\' +#define kNewFSSeparatorAlt '/' #define kNewFSUpDir ".." -#define kNewFSRoot "C:\\" +#define kNewFSRoot "\\" +#define kNewFSRootAlt "/" #define kNewFSLF '\r' #define kNewFSEOF (-1) @@ -81,7 +82,7 @@ default. /// Start After the PM headers, pad 1024 bytes. #define kNewFSStartLba (1024) -#define kNewFSCatalogStartAddress ((2048) + sizeof(NewPartitionBlock) + sizeof(NewCatalog)) +#define kNewFSCatalogStartAddress ((2048) + sizeof(NFS_ROOT_PARTITION_BLOCK) + sizeof(NFS_CATALOG_STRUCT)) #define kResourceTypeDialog (10) #define kResourceTypeString (11) @@ -112,7 +113,7 @@ enum }; /// @brief Catalog type. -struct PACKED NewCatalog final +struct PACKED NFS_CATALOG_STRUCT final { NewCharType Name[kNewFSNodeNameLen]; NewCharType Mime[kNewFSMimeNameLen]; @@ -141,9 +142,9 @@ struct PACKED NewCatalog final /// @note The way we store is way different than how other filesystems do, specific chunk of code are /// written into either the data fork or resource fork, the resource fork is reserved for file metadata. /// whereas the data fork is reserved for file data. -struct PACKED NewFork final +struct PACKED NFS_FORK_STRUCT final { - NewCharType ForkName[kNewFSForkNameLen]; + NewCharType ForkName[kNewFSForkNameLen]; Kernel::Char CatalogName[kNewFSNodeNameLen]; Kernel::Int32 Flags; @@ -153,15 +154,15 @@ struct PACKED NewFork final Kernel::Int32 ResourceKind; Kernel::Int32 ResourceFlags; - Kernel::Lba DataOffset; // 8 Where to look for this data? - Kernel::SizeT DataSize; /// Data size according using sector count. + Kernel::Lba DataOffset; // 8 Where to look for this data? + Kernel::SizeT DataSize; /// Data size according using sector count. Kernel::Lba NextSibling; Kernel::Lba PreviousSibling; }; /// @brief Partition block type -struct PACKED NewPartitionBlock final +struct PACKED NFS_ROOT_PARTITION_BLOCK final { NewCharType Ident[kNewFSIdentLen]; NewCharType PartitionName[kPartLen]; @@ -169,7 +170,7 @@ struct PACKED NewPartitionBlock final Kernel::Int32 Flags; Kernel::Int32 Kind; - Kernel::Lba StartCatalog; + Kernel::Lba StartCatalog; Kernel::SizeT CatalogCount; Kernel::SizeT DiskSize; @@ -187,7 +188,6 @@ struct PACKED NewPartitionBlock final namespace Kernel { - enum { kNewFSSubDriveA, @@ -224,47 +224,47 @@ namespace Kernel /// @param catalog it's catalog /// @param theFork the fork itself. /// @return the fork - _Output NewFork* CreateFork(_Input NewCatalog* catalog, - _Input NewFork& theFork); + _Output NFS_FORK_STRUCT* CreateFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input NFS_FORK_STRUCT& theFork); /// @brief Find fork inside New filesystem. /// @param catalog the catalog. /// @param name the fork name. /// @return the fork. - _Output NewFork* FindFork(_Input NewCatalog* catalog, + _Output NFS_FORK_STRUCT* FindFork(_Input NFS_CATALOG_STRUCT* catalog, _Input const Char* name, Boolean dataOrRsrc); - _Output Void RemoveFork(_Input NewFork* fork); + _Output Void RemoveFork(_Input NFS_FORK_STRUCT* fork); - _Output Void CloseFork(_Input NewFork* fork); + _Output Void CloseFork(_Input NFS_FORK_STRUCT* fork); - _Output NewCatalog* FindCatalog(_Input const char* catalogName, Lba& outLba); + _Output NFS_CATALOG_STRUCT* FindCatalog(_Input const char* catalogName, Lba& outLba); - _Output NewCatalog* GetCatalog(_Input const char* name); + _Output NFS_CATALOG_STRUCT* GetCatalog(_Input const char* name); - _Output NewCatalog* CreateCatalog(_Input const char* name, + _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const char* name, _Input const Int32& flags, _Input const Int32& kind); - _Output NewCatalog* CreateCatalog(_Input const char* name); + _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const char* name); - bool WriteCatalog(_Input _Output NewCatalog* catalog, + bool WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, voidPtr data, SizeT sizeOfData, _Input const char* forkName); - VoidPtr ReadCatalog(_Input _Output NewCatalog* catalog, + VoidPtr ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT dataSz, _Input const char* forkName); - bool Seek(_Input _Output NewCatalog* catalog, SizeT off); + bool Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off); - SizeT Tell(_Input _Output NewCatalog* catalog); + SizeT Tell(_Input _Output NFS_CATALOG_STRUCT* catalog); bool RemoveCatalog(_Input const Char* catalog); - bool CloseCatalog(_InOut NewCatalog* catalog); + bool CloseCatalog(_InOut NFS_CATALOG_STRUCT* catalog); /// @brief Make a EPM+NewFS drive out of the disk. /// @param drive The drive to write on. @@ -300,8 +300,8 @@ namespace Kernel /// @param DrvIndex drive index. /// @return Kernel::Int32 fs_newfs_write(Kernel::MountpointInterface* Mnt, - Kernel::DriveTrait& DrvTrait, - Kernel::Int32 DrvIndex); + Kernel::DriveTrait& DrvTrait, + Kernel::Int32 DrvIndex); /// @brief Read from newfs disk. /// @param Mnt mounted interface. @@ -309,5 +309,5 @@ Kernel::Int32 fs_newfs_write(Kernel::MountpointInterface* Mnt, /// @param DrvIndex drive index. /// @return Kernel::Int32 fs_newfs_read(Kernel::MountpointInterface* Mnt, - Kernel::DriveTrait& DrvTrait, - Kernel::Int32 DrvIndex); + Kernel::DriveTrait& DrvTrait, + Kernel::Int32 DrvIndex); diff --git a/Kernel/FirmwareKit/EFI.hxx b/Kernel/FirmwareKit/EFI.hxx index c83d62fe..ab705038 100644 --- a/Kernel/FirmwareKit/EFI.hxx +++ b/Kernel/FirmwareKit/EFI.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/FirmwareKit/EFI/API.hxx b/Kernel/FirmwareKit/EFI/API.hxx index 691c19d7..3bb1fb76 100644 --- a/Kernel/FirmwareKit/EFI/API.hxx +++ b/Kernel/FirmwareKit/EFI/API.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -9,13 +9,15 @@ #include <FirmwareKit/EFI/EFI.hxx> #include <FirmwareKit/Handover.hxx> -#include <KernelKit/MSDOS.hpp> +#include <KernelKit/MSDOS.hxx> #include <KernelKit/PE.hxx> #ifdef __NEWBOOT__ // forward decl. class BTextWriter; +#define cWebsiteMacro "https://zka-mobile.com/help" + #define __BOOTKIT_NO_INCLUDE__ 1 #include <BootKit/BootKit.hxx> @@ -76,7 +78,6 @@ Bascially frees everything we have in the EFI side. inline void ThrowError(const EfiCharType* ErrorCode, const EfiCharType* Reason) noexcept { -#ifdef __DEBUG__ ST->ConOut->OutputString(ST->ConOut, L"\r*** STOP ***\r"); ST->ConOut->OutputString(ST->ConOut, L"*** Error: "); @@ -86,36 +87,29 @@ Bascially frees everything we have in the EFI side. ST->ConOut->OutputString(ST->ConOut, Reason); ST->ConOut->OutputString(ST->ConOut, L" ***\r"); -#endif // ifdef __DEBUG__ #ifdef __NEWBOOT__ - GXInit(); - - GXDrawImg(NewBootFatal, NEWBOOTFATAL_HEIGHT, NEWBOOTFATAL_WIDTH, - (kHandoverHeader->f_GOP.f_Width - NEWBOOTFATAL_WIDTH) / 2, - (kHandoverHeader->f_GOP.f_Height - NEWBOOTFATAL_HEIGHT) / 2); - - GXFini(); + // Show the QR code now. - /// Show the QR code now. + constexpr auto cVer = 4; + const auto cECC = qr::Ecc::H; + const auto cInput = cWebsiteMacro; + const auto cInputLen = StrLen(cWebsiteMacro); - constexpr auto ver = 4; - auto ecc = qr::Ecc::H; - auto str = "https://el-mahrouss-logic.com/"; - auto len = StrLen("https://el-mahrouss-logic.com/"); + qr::Qr<cVer> encoder; + qr::QrDelegate encoderDelegate; - qr::Qr<ver> encoder; - qr::QrDelegate encoderDelegate; + encoder.encode(cInput, cInputLen, cECC, 0); // Manual mask 0 - encoder.encode(str, len, ecc, 0); // Manual mask 0 + const auto cWhereStartX = (kHandoverHeader->f_GOP.f_Width - encoder.side_size()) - 20; + const auto cWhereStartY = (kHandoverHeader->f_GOP.f_Height - encoder.side_size()) / 2; - /// tell delegate to draw encoded QR. - encoderDelegate.draw<ver>(encoder, (kHandoverHeader->f_GOP.f_Width - encoder.side_size()) - 20, - (kHandoverHeader->f_GOP.f_Height - encoder.side_size()) / 2); - -#endif // ifdef __NEWBOOT__ + // tell delegate to draw encoded QR now. + encoderDelegate.draw<cVer>(encoder, cWhereStartX, + cWhereStartY); EFI::Stop(); +#endif // ifdef __NEWBOOT__ } } // namespace EFI diff --git a/Kernel/FirmwareKit/EFI/EFI.hxx b/Kernel/FirmwareKit/EFI/EFI.hxx index 922044d4..573778ea 100644 --- a/Kernel/FirmwareKit/EFI/EFI.hxx +++ b/Kernel/FirmwareKit/EFI/EFI.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -46,7 +46,7 @@ typedef UInt64 EfiStatusType; /// This is like NT's Win32 HANDLE type. typedef struct EfiHandle { -} * EfiHandlePtr; +}* EfiHandlePtr; /* UEFI uses wide characters by default. */ typedef WideChar EfiCharType; @@ -589,11 +589,12 @@ typedef struct EfiSystemTable { EfiGUID VendorGUID; VoidPtr VendorTable; - } * ConfigurationTable; + }* ConfigurationTable; } EfiSystemTable; -#define kEfiOk 0 -#define kEfiFail -1 +#define kEfiOk 0 +#define kEfiFail -1 +#define kBufferTooSmall 5 #define EFI_EXTERN_C extern "C" @@ -721,8 +722,10 @@ typedef struct EfiFileProtocol EfiStatusType(EFI_API* ReadEx)(EfiFileProtocol* This, struct EfiIOToken* Token); + EfiStatusType(EFI_API* WriteEx)(EfiFileProtocol* This, struct EfiIOToken* Token); + EfiStatusType(EFI_API* FlushEx)(EfiFileProtocol* This, struct EfiIOToken* Token); } EfiFileProtocol, *EfiFileProtocolPtr; diff --git a/Kernel/FirmwareKit/EPM.hxx b/Kernel/FirmwareKit/EPM.hxx index 9669e324..2766abf6 100644 --- a/Kernel/FirmwareKit/EPM.hxx +++ b/Kernel/FirmwareKit/EPM.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -17,36 +17,6 @@ #define kEPMFilesystemLength (16) #define kEPMMagicLength (5) -/* The first 0 > 128 addresses of a disk contains these headers. */ - -/// @brief EPM GUID structure. -typedef struct BlockGUID -{ - Kernel::UInt32 Data1; - Kernel::UInt16 Data2; - Kernel::UInt16 Data3; - Kernel::UInt8 Data4[8]; -} BlockGUID; - -/** - * @brief The EPM boot block. - * @note NumBlock and LbaStart are ignored on some platforms. - */ -struct PACKED BootBlock -{ - Kernel::Char Magic[kEPMMagicLength]; - Kernel::Char Name[kEPMNameLength]; - BlockGUID Uuid; - Kernel::Int32 Version; - Kernel::Int64 NumBlocks; - Kernel::Int64 SectorSz; - Kernel::Int64 LbaStart; - Kernel::Int16 Kind; - Kernel::Int32 FsVersion; - Kernel::Char Fs[kEPMFilesystemLength]; /* NewFS, ffs2... */ - Kernel::Char Reserved[409]; // to fill a full sector. -}; - /* @brief AMD64 magic for EPM */ #define kEPMMagic86 "EPMAM" @@ -79,19 +49,6 @@ struct PACKED BootBlock #define kEPMMagicError "EPM??" -///! @brief Version kind enum. -///! @brief Use in boot block version field. - -enum kEPMKind -{ - kEPMMpUx = 0xcf, // Bridge or other embedded OS - kEPMLinux = 0x8f, - kEPMBSD = 0x9f, - kEPMNewOS = 0x1f, // This kernel. -}; - -typedef struct BootBlock BootBlockType; - #ifdef __NEWOS_AMD64__ #define kEPMMagic kEPMMagic86 #else @@ -104,7 +61,7 @@ typedef struct BootBlock BootBlockType; ///! @brief partition must start at this address. ///! Anything below is reserved for Data backup by the Main OS. -#define kEPMStartPartitionBlk (sizeof(BootBlock)) +#define kEPMStartPartitionBlk (sizeof(_BOOT_BLOCK_STRUCT)) ///! @brief Current EPM revision #define kEPMRevision (0xAD) @@ -113,6 +70,47 @@ typedef struct BootBlock BootBlockType; /// !@brief EPM base address #define kEpmBase (0U) -/// END OF SPECS +/* The first 0 > 128 addresses of a disk contains these headers. */ + +/// @brief EPM GUID structure. +typedef struct _BLOCK_GUID_STRUCT +{ + Kernel::UInt32 Data1; + Kernel::UInt16 Data2; + Kernel::UInt16 Data3; + Kernel::UInt8 Data4[8]; +} BLOCK_GUID_STRUCT; + +/** + * @brief The EPM boot block. + * @note NumBlock and LbaStart are ignored on some platforms. + */ +struct PACKED _BOOT_BLOCK_STRUCT +{ + Kernel::Char Magic[kEPMMagicLength]; + Kernel::Char Name[kEPMNameLength]; + BLOCK_GUID_STRUCT Uuid; + Kernel::Int32 Version; + Kernel::Int64 NumBlocks; + Kernel::Int64 SectorSz; + Kernel::Int64 LbaStart; + Kernel::Int16 Kind; + Kernel::Int32 FsVersion; + Kernel::Char Fs[kEPMFilesystemLength]; /* NewFS, ffs2... */ + Kernel::Char Reserved[409]; // to fill a full sector. +}; + +///! @brief Version kind enum. +///! @brief Use in boot block version field. + +enum +{ + kEPMMpUx = 0xcf, // Bridge or other embedded OS + kEPMLinux = 0x8f, + kEPMBSD = 0x9f, + kEPMNewOS = 0x1f, // This kernel. +}; + +typedef struct _BOOT_BLOCK_STRUCT BOOT_BLOCK_STRUCT; #endif // ifndef __FIRMWARE_EPM_HXX__ diff --git a/Kernel/FirmwareKit/Handover.hxx b/Kernel/FirmwareKit/Handover.hxx index 02e5fb21..01f2be2c 100644 --- a/Kernel/FirmwareKit/Handover.hxx +++ b/Kernel/FirmwareKit/Handover.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -11,7 +11,7 @@ * @version 0.3 * @date 2024-02-23 * - * @copyright Copyright (c) 2024, Zeta Electronics Corporation + * @copyright Copyright (c) 2024, ZKA Technologies * */ @@ -76,7 +76,7 @@ it tells us more about it and IS format independent. struct { VoidPtr f_SmBios; - VoidPtr f_RsdPtr; + VoidPtr f_VendorPtr; } f_HardwareTables; struct @@ -100,7 +100,7 @@ it tells us more about it and IS format independent. }; /// @brief Bootloader main type. - typedef void (*BootMainKind)(Kernel::HEL::HandoverInformationHeader* handoverInfo); + typedef void (*BootMainKind)(HandoverInformationHeader* handoverInfo); /// @brief Alias of bootloader main type. typedef void (*HandoverProc)(HandoverInformationHeader* handoverInfo); diff --git a/Kernel/HALKit/64x0/HalVirtualMemory.cxx b/Kernel/HALKit/64x0/HalVirtualMemory.cxx index f62f888f..9aeb6b8e 100644 --- a/Kernel/HALKit/64x0/HalVirtualMemory.cxx +++ b/Kernel/HALKit/64x0/HalVirtualMemory.cxx @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> using namespace Kernel; diff --git a/Kernel/HALKit/64x0/ReadMe.md b/Kernel/HALKit/64x0/ReadMe.md index a22d0385..2e72d5bf 100644 --- a/Kernel/HALKit/64x0/ReadMe.md +++ b/Kernel/HALKit/64x0/ReadMe.md @@ -1,4 +1,4 @@ 64x0 Hardware Abstraction Layer -- Supported CPU: Zeta Electronics Corporation 64x0 +- Supported CPU: ZKA Technologies 64x0 - Supported Firmware: CoreBoot
\ No newline at end of file diff --git a/Kernel/HALKit/AMD64/CPUID.hxx b/Kernel/HALKit/AMD64/CPUID.hxx index 602b2466..5c05277e 100644 --- a/Kernel/HALKit/AMD64/CPUID.hxx +++ b/Kernel/HALKit/AMD64/CPUID.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: CPUID.hxx Purpose: CPUID flags. diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index ca6a7417..6f66ae5b 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -1,14 +1,14 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <Modules/ACPI/ACPIFactoryInterface.hxx> -#include <HALKit/AMD64/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> #include <NewKit/String.hpp> #include <ArchKit/ArchKit.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> namespace Kernel { @@ -104,7 +104,8 @@ namespace Kernel { SDT& sdt = *reinterpret_cast<SDT*>(xsdt->AddressArr[index]); - kcout << "ACPI: Revision: " << number(sdt.CreatorID) << endl; + kcout << "ACPI: Checksum: " << number(sdt.Checksum) << endl; + kcout << "ACPI: Revision: " << number(sdt.Revision) << endl; for (short signature_index = 0; signature_index < cAcpiSignatureLength; ++signature_index) { diff --git a/Kernel/HALKit/AMD64/HalAPIC.cxx b/Kernel/HALKit/AMD64/HalAPIC.cxx new file mode 100644 index 00000000..34ec7494 --- /dev/null +++ b/Kernel/HALKit/AMD64/HalAPIC.cxx @@ -0,0 +1,36 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#include <Modules/ACPI/ACPIFactoryInterface.hxx> +#include <HALKit/AMD64/Processor.hxx> + +namespace Kernel::HAL +{ + /// @brief Read from APIC controller. + /// @param reg register. + UInt32 APICController::Read(UInt32 reg) noexcept + { + MUST_PASS(this->fApic); + + UInt32 volatile* ioapic = (UInt32 volatile*)this->fApic; + ioapic[0] = (reg & 0xff); + + return ioapic[4]; + } + + /// @brief Write to APIC controller. + /// @param reg register. + /// @param value value. + Void APICController::Write(UInt32 reg, UInt32 value) noexcept + { + MUST_PASS(this->fApic); + + UInt32 volatile* ioapic = (UInt32 volatile*)this->fApic; + + ioapic[0] = (reg & 0xFF); + ioapic[4] = value; + } +} // namespace Kernel::HAL diff --git a/Kernel/HALKit/AMD64/HalNewBoot.asm b/Kernel/HALKit/AMD64/HalBoot.asm index 5f0342a3..ab8273a1 100644 --- a/Kernel/HALKit/AMD64/HalNewBoot.asm +++ b/Kernel/HALKit/AMD64/HalBoot.asm @@ -2,7 +2,7 @@ ;; * ======================================================== ;; * ;; * Kernel -;; * Copyright Zeta Electronics Corporation, all rights reserved. +;; * Copyright ZKA Technologies, all rights reserved. ;; * ;; * ======================================================== ;; */ diff --git a/Kernel/HALKit/AMD64/HalControlRegister.s b/Kernel/HALKit/AMD64/HalControlRegister.s index 20eda96f..34b3da90 100644 --- a/Kernel/HALKit/AMD64/HalControlRegister.s +++ b/Kernel/HALKit/AMD64/HalControlRegister.s @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx index f41ee55e..29c0f3c7 100644 --- a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -14,7 +14,7 @@ EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp) { Kernel::kcout << "newoskrnl: General Protection Fault, caused by " - << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); + << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName(); Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } @@ -25,7 +25,7 @@ EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) { Kernel::kcout << "newoskrnl: Segmentation Fault, caused by " - << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); + << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName(); Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } @@ -36,7 +36,7 @@ EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) { Kernel::kcout << "newoskrnl: Math error, caused by " - << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); + << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName(); Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } @@ -47,7 +47,7 @@ EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) { Kernel::kcout << "newoskrnl: Execution error, caused by " - << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); + << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName(); Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } @@ -58,7 +58,7 @@ EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) { Kernel::kcout << "newoskrnl: Invalid interrupt, caused by " - << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); + << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName(); Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx index 94fe68ad..48d737fe 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx @@ -1,11 +1,11 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <Modules/ACPI/ACPIFactoryInterface.hxx> -#include <HALKit/AMD64/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> #include <NewKit/KernelCheck.hpp> #include <ArchKit/ArchKit.hpp> #include <KernelKit/Semaphore.hpp> @@ -17,10 +17,14 @@ #define kAPIC_SIPI_Vector 0x00500 #define kAPIC_EIPI_Vector 0x00400 +#define kAPIC_BASE_MSR 0x1B +#define kAPIC_BASE_MSR_BSP 0x100 +#define kAPIC_BASE_MSR_ENABLE 0x800 + /// @brief assembly routine. internal use only. EXTERN_C void _hal_enable_smp(void); -/// @note: _hal_switch_context +/// @note: _hal_switch_context is internal /////////////////////////////////////////////////////////////////////////////////////// @@ -57,8 +61,8 @@ namespace Kernel::HAL } Selector; }; - STATIC voidPtr kApicMadt = nullptr; - STATIC const char* kApicSignature = "APIC"; + STATIC VoidPtr kApicMadt = nullptr; + STATIC const Char* kApicSignature = "APIC"; /// @brief Multiple APIC Descriptor Table. struct MadtType final : public SDT @@ -122,11 +126,7 @@ namespace Kernel::HAL UInt32 fKind{0}; } kApicMadtAddresses[255] = {}; - STATIC SizeT kApicMadtAddressesCount = 0UL; - STATIC UIntPtr cBaseAddressAPIC = 0xFEE00000; - - /// @brief this will help us schedule our cores. - STATIC Boolean* cProgramInitialized = nullptr; + STATIC SizeT kApicMadtAddressesCount = 0UL; enum { @@ -142,7 +142,7 @@ namespace Kernel::HAL /// @return Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress) { - Kernel::ke_dma_write(targetAddress, kAPIC_ICR_High, apicId << 24); + Kernel::ke_dma_write(targetAddress, kAPIC_ICR_High, (apicId << 24)); Kernel::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_SIPI_Vector | vector); } @@ -159,25 +159,23 @@ namespace Kernel::HAL Kernel::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_EIPI_Vector | vector); } - STATIC HAL::StackFramePtr cFramePtr = nullptr; - STATIC Int32 cSMPInterrupt = 0x40; - - EXTERN_C Void hal_apic_acknowledge_cont(Void) - { - kcout << "newoskrnl: stopping core...\r"; - ke_stop(RUNTIME_CHECK_BOOTSTRAP); - } + STATIC HAL::StackFramePtr cFramePtr = nullptr; + STATIC Int32 cSMPInterrupt = 34; + /// @brief Current context getter. + /// @retval StackFramePtr the current context. EXTERN_C StackFramePtr _hal_leak_current_context(Void) { return cFramePtr; } + /// @internal EXTERN_C Void hal_apic_acknowledge(Void) { - hal_apic_acknowledge_cont(); + kcout << "newoskrnl: acknowledge APIC.\r"; } + /// @internal EXTERN_C Void _hal_switch_context(HAL::StackFramePtr stackFrame) { hal_switch_context(stackFrame); @@ -187,17 +185,37 @@ namespace Kernel::HAL { Semaphore sem; - HardwareTimer timer(Seconds(5)); + constexpr auto cSeconds = 1U; + + HardwareTimer timer(Seconds(cSeconds)); sem.LockOrWait(&ProcessScheduler::The().Leak().TheCurrent().Leak(), &timer); cFramePtr = stackFrame; - /// yes the exception field contains the core id. - hal_send_start_ipi(stackFrame->Rcx, cSMPInterrupt, cBaseAddressAPIC); - sem.Unlock(); } + STATIC auto cAPICAddress = 0x0FEC00000; + + STATIC Void cpu_set_apic_base(UIntPtr apic) + { + UInt32 edx = 0; + UInt32 eax = (apic & 0xfffff0000) | kAPIC_BASE_MSR_ENABLE; + + edx = (apic >> 32) & 0x0f; + + hal_set_msr(kAPIC_BASE_MSR, eax, edx); + } + + STATIC UIntPtr cpu_get_apic_base(Void) + { + UInt32 eax, edx; + + hal_get_msr(kAPIC_BASE_MSR, &eax, &edx); + + return (eax & 0xfffff000) | ((UIntPtr)(edx & 0x0f) << 32); + } + /// @brief Fetch and enable cores inside main CPU. /// @param rsdPtr RSD PTR structure. Void hal_system_get_cores(voidPtr rsdPtr) @@ -209,47 +227,14 @@ namespace Kernel::HAL { MadtType* madt = reinterpret_cast<MadtType*>(kApicMadt); - constexpr auto cMaxProbableCores = 4; // the amount of cores we want. - constexpr auto cStartAt = 0; // start here to avoid boot core. - - for (SizeT coreAt = cStartAt; coreAt < cMaxProbableCores; ++coreAt) - { - if (madt->MadtRecords[coreAt].Flags < kThreadBoot) // if local apic. - { - MadtType::MadtAddress& madtRecord = madt->MadtRecords[coreAt]; - - // then register as a core for scheduler. - kcout << "newoskrnl: Register APIC.\r"; - - kApicMadtAddresses[kApicMadtAddressesCount].fAddress = madtRecord.Address; - kApicMadtAddresses[kApicMadtAddressesCount].fKind = madt->MadtRecords[coreAt].Flags; + cpu_set_apic_base(cpu_get_apic_base()); - ++kApicMadtAddressesCount; - } - } + // set SVR register to bit 8 to start recieve interrupts. - /////////////////////////////////////////////////////////////////////////// - /// Start local APIC now. - /////////////////////////////////////////////////////////////////////////// - - auto flagsSet = Kernel::ke_dma_read(cBaseAddressAPIC, 0xF0); // SVR register. - - // enable APIC. + auto flagsSet = Kernel::ke_dma_read(cAPICAddress, 0xF0); // SVR register. flagsSet |= 0x100; - Kernel::ke_dma_write(cBaseAddressAPIC, 0xF0, flagsSet); - - /// Set sprurious interrupt vector. - Kernel::ke_dma_write(cBaseAddressAPIC, 0xF0, 0x100 | 0xFF); - - // highest task priority. for our realtime kernel. - Kernel::ke_dma_write(cBaseAddressAPIC, 0x21, 0); - - cProgramInitialized = new Boolean(true); - - constexpr auto cWhatCore = 1; - - hal_send_start_ipi(cWhatCore, cSMPInterrupt, cBaseAddressAPIC); + Kernel::ke_dma_write(cAPICAddress, 0xF0, flagsSet | 0x100); } else { diff --git a/Kernel/HALKit/AMD64/HalDebugOutput.cxx b/Kernel/HALKit/AMD64/HalDebugOutput.cxx index 3dd70dc6..36ae96b0 100644 --- a/Kernel/HALKit/AMD64/HalDebugOutput.cxx +++ b/Kernel/HALKit/AMD64/HalDebugOutput.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -27,7 +27,7 @@ namespace Kernel /// @brief Init COM1. /// @return - bool serial_init() noexcept + bool hal_serial_init() noexcept { #ifdef __DEBUG__ if (kState == kStateReady || kState == kStateTransmit) @@ -64,7 +64,7 @@ namespace Kernel EXTERN_C void ke_io_write(const char* bytes) { #ifdef __DEBUG__ - Detail::serial_init(); + Detail::hal_serial_init(); if (!bytes || Detail::kState != kStateReady) return; @@ -74,7 +74,10 @@ namespace Kernel Detail::kState = kStateTransmit; SizeT index = 0; - SizeT len = rt_string_len(bytes, 256); + SizeT len = 0; + + index = 0; + len = rt_string_len(bytes, 255); while (index < len) { @@ -92,7 +95,7 @@ namespace Kernel EXTERN_C void ke_io_read(const char* bytes) { #ifdef __DEBUG__ - Detail::serial_init(); + Detail::hal_serial_init(); if (!bytes || Detail::kState != kStateReady) return; diff --git a/Kernel/HALKit/AMD64/HalDebugPort.cxx b/Kernel/HALKit/AMD64/HalDebugPort.cxx index a29a8129..8a161cc7 100644 --- a/Kernel/HALKit/AMD64/HalDebugPort.cxx +++ b/Kernel/HALKit/AMD64/HalDebugPort.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/AMD64/HalDescriptorLoader.cpp b/Kernel/HALKit/AMD64/HalDescriptorLoader.cxx index 964b402a..7ded9259 100644 --- a/Kernel/HALKit/AMD64/HalDescriptorLoader.cpp +++ b/Kernel/HALKit/AMD64/HalDescriptorLoader.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -61,13 +61,14 @@ namespace Kernel::HAL { MUST_PASS(baseIdt[i]); - Detail::kInterruptVectorTable[i].Selector = kGdtCodeSelector; + Detail::kInterruptVectorTable[i].Selector = (i == kSyscallRoute) ? ((3 * 8) | 3) : kGdtCodeSelector; Detail::kInterruptVectorTable[i].Ist = 0x0; Detail::kInterruptVectorTable[i].TypeAttributes = kInterruptGate; - Detail::kInterruptVectorTable[i].OffsetLow = ((UIntPtr)baseIdt[i] & 0xFFFF); - Detail::kInterruptVectorTable[i].OffsetMid = (((UIntPtr)baseIdt[i] >> 16) & 0xFFFF); + Detail::kInterruptVectorTable[i].OffsetLow = ((UIntPtr)baseIdt[i] & __INT16_MAX__); + Detail::kInterruptVectorTable[i].OffsetMid = (((UIntPtr)baseIdt[i] >> 16) & __INT16_MAX__); Detail::kInterruptVectorTable[i].OffsetHigh = - (((UIntPtr)baseIdt[i] >> 32) & 0xFFFFFFFF); + (((UIntPtr)baseIdt[i] >> 32) & __INT32_MAX__); + Detail::kInterruptVectorTable[i].Zero = 0x0; } diff --git a/Kernel/HALKit/AMD64/HalHart.cpp b/Kernel/HALKit/AMD64/HalHart.cxx index 2a12ec50..adbf148c 100644 --- a/Kernel/HALKit/AMD64/HalHart.cpp +++ b/Kernel/HALKit/AMD64/HalHart.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/AMD64/HalInstallTIB.asm b/Kernel/HALKit/AMD64/HalInstallTIB.asm deleted file mode 100644 index aad5d6d0..00000000 --- a/Kernel/HALKit/AMD64/HalInstallTIB.asm +++ /dev/null @@ -1,24 +0,0 @@ -;; /* -;; * ======================================================== -;; * -;; * Kernel -;; * Copyright Zeta Electronics Corporation, all rights reserved. -;; * -;; * ======================================================== -;; */ - -[bits 64] - -[global rt_install_tib] - -section .text - -;; changed: rs, fs -;; expected: rcx, rdx - -rt_install_tib: - mov rcx, gs ;; TIB -> Thread Information Block - mov rdx, fs ;; PIB -> Process Information Block - ret - -;; //////////////////////////////////////////////////// ;; diff --git a/Kernel/HALKit/AMD64/HalInterruptAPI.asm b/Kernel/HALKit/AMD64/HalInterruptAPI.asm index 016c9cd8..c09d5a06 100644 --- a/Kernel/HALKit/AMD64/HalInterruptAPI.asm +++ b/Kernel/HALKit/AMD64/HalInterruptAPI.asm @@ -1,7 +1,7 @@ ;; /* ;; * --------------------------------------------------- ;; * -;; * Copyright Zeta Electronics Corporation, all rights reserved. +;; * Copyright ZKA Technologies, all rights reserved. ;; * ;; * File: HalInterruptAPI.asm ;; * Purpose: Interrupt routing, redirect raw interrupts into their handlers. @@ -121,53 +121,16 @@ IntNormal 31 [extern hal_apic_acknowledge] -__NEW_INT_32: -;; make this active, SMP works again. -%if 0 +__NEW_INT_34: push rax - push rcx - push rdx - push rbx - push rbp - push rsi - push rdi - push r8 - push r9 - push r10 - push r11 - push r12 - push r13 - push r14 - push r15 - - jmp hal_apic_acknowledge - - pop r15 - pop r14 - pop r13 - pop r12 - pop r11 - pop r10 - pop r9 - pop r8 - pop rdi - pop rsi - pop rbp - pop rbx - pop rdx - pop rcx + call hal_apic_acknowledge pop rax - mov rax, 0 - - ;; tell there local apic that we're done. - mov [0xFEE00000 + 0xB0], rax ; LAPIC_EOI -%endif iretq -IntNormal 33 +IntNormal 32 -IntNormal 34 +IntNormal 33 IntNormal 35 IntNormal 36 IntNormal 37 diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index 628314b5..1628e5e9 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -9,21 +9,26 @@ #include <FirmwareKit/Handover.hxx> #include <KernelKit/FileManager.hpp> #include <KernelKit/Framebuffer.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <KernelKit/PEFCodeManager.hxx> #include <KernelKit/ProcessScheduler.hxx> -#include <KernelKit/UserHeap.hpp> -#include <NewKit/Json.hpp> +#include <KernelKit/ProcessHeap.hxx> +#include <NewKit/Json.hxx> #include <Modules/CoreCG/Accessibility.hxx> #include <KernelKit/CodeManager.hpp> #include <Modules/ACPI/ACPIFactoryInterface.hxx> #include <NetworkKit/IPCEP.hxx> +#include <CFKit/Property.hpp> -#define KERNEL_INIT(X) X; \ +#define mInitKernel(X) \ + X; \ Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP); +Kernel::Property cKernelVersion; +Kernel::Property cAutoFormatDisk; + /// @brief This symbol is the kernel main symbol. EXTERN_C void KeMain(); @@ -32,7 +37,7 @@ EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; struct PACKED HeapAllocInfo final { Kernel::VoidPtr fThe; - Kernel::Size fTheSz; + Kernel::Size fTheSz; }; struct PACKED ProcessBlockInfo final @@ -46,7 +51,7 @@ struct PACKED ProcessExitInfo final STATIC constexpr auto cReasonLen = 512; Kernel::Int64 fCode; - Kernel::Char fReason[cReasonLen]; + Kernel::Char fReason[cReasonLen]; }; namespace Kernel::HAL @@ -121,9 +126,9 @@ EXTERN_C void hal_init_platform( constexpr auto cCatalogCreate = 0x22; constexpr auto cRebootInterrupt = 0x23; constexpr auto cShutdownInterrupt = 0x24; - constexpr auto cLPCSendMsg = 0x25; - constexpr auto cLPCOpenMsg = 0x26; - constexpr auto cLPCCloseMsg = 0x27; + constexpr auto cLPCSendMsg = 0x25; + constexpr auto cLPCOpenMsg = 0x26; + constexpr auto cLPCCloseMsg = 0x27; constexpr auto cLPCSanitizeMsg = 0x28; kSyscalls[cSerialAlertInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { @@ -142,8 +147,9 @@ EXTERN_C void hal_init_platform( kSyscalls[cNewInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { // get HAC struct. HeapAllocInfo* rdxInf = reinterpret_cast<HeapAllocInfo*>(rdx); - - if (!rdxInf) return; + + if (!rdxInf) + return; // assign the fThe field with the pointer. rdxInf->fThe = Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().New(rdxInf->fTheSz); @@ -153,7 +159,8 @@ EXTERN_C void hal_init_platform( // get HAC struct. HeapAllocInfo* rdxInf = reinterpret_cast<HeapAllocInfo*>(rdx); - if (!rdxInf) return; + if (!rdxInf) + return; // delete ptr with sz in mind. Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Delete(rdxInf->fThe, rdxInf->fTheSz); @@ -161,8 +168,9 @@ EXTERN_C void hal_init_platform( kSyscalls[cTlsInstallInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { ProcessBlockInfo* rdxPb = reinterpret_cast<ProcessBlockInfo*>(rdx); - - if (!rdxPb) return; + + if (!rdxPb) + return; // install the fTIB and fPIB. rt_install_tib(rdxPb->fTIB, rdxPb->fPIB); @@ -170,8 +178,9 @@ EXTERN_C void hal_init_platform( kSyscalls[cExitInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { ProcessExitInfo* rdxEi = reinterpret_cast<ProcessExitInfo*>(rdx); - - if (!rdxEi) return; + + if (!rdxEi) + return; Kernel::kcout << "newoskrnl: " << rdxEi->fReason << "\r"; Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Exit(rdxEi->fCode); @@ -179,19 +188,20 @@ EXTERN_C void hal_init_platform( kSyscalls[cLastExitInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { ProcessExitInfo* rdxEi = reinterpret_cast<ProcessExitInfo*>(rdx); - - if (!rdxEi) return; - rdxEi->fCode = Kernel::rt_get_exit_code(); + if (!rdxEi) + return; + + rdxEi->fCode = Kernel::rt_get_exit_code(); }; kSyscalls[cRebootInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { - Kernel::ACPIFactoryInterface acpi(kHandoverHeader->f_HardwareTables.f_RsdPtr); + Kernel::ACPIFactoryInterface acpi(kHandoverHeader->f_HardwareTables.f_VendorPtr); acpi.Reboot(); }; kSyscalls[cShutdownInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { - Kernel::ACPIFactoryInterface acpi(kHandoverHeader->f_HardwareTables.f_RsdPtr); + Kernel::ACPIFactoryInterface acpi(kHandoverHeader->f_HardwareTables.f_VendorPtr); acpi.Shutdown(); }; @@ -206,7 +216,20 @@ EXTERN_C void hal_init_platform( kSyscalls[cRebootInterrupt].Leak().Leak()->fHooked = true; kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fHooked = true; - Kernel::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); + // newoskrnl version 1.00 + Kernel::StringView strVer(cMaxPropLen); + strVer += "\\Properties\\KernelVersion"; + + cKernelVersion.GetKey() = strVer; + cKernelVersion.GetValue() = __MAHROUSS__; + + Kernel::StringView strAutoMount(cMaxPropLen); + strAutoMount += "\\Properties\\AutoMountFS?"; + + cAutoFormatDisk.GetKey() = strAutoMount; + cAutoFormatDisk.GetValue() = Yes; + + Kernel::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); - KERNEL_INIT(KeMain()); + mInitKernel(KeMain()); } diff --git a/Kernel/HALKit/AMD64/HalKernelMouse.cxx b/Kernel/HALKit/AMD64/HalKernelMouse.cxx index 9cad6d35..9b3467fa 100644 --- a/Kernel/HALKit/AMD64/HalKernelMouse.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMouse.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -14,16 +14,16 @@ EXTERN_C Kernel::Boolean _hal_draw_mouse(); EXTERN_C Kernel::Void _hal_init_mouse(); -STATIC Kernel::Int32 kPrevX = 10; -STATIC Kernel::Int32 kPrevY = 10; -STATIC Kernel::Int32 kX = 10; -STATIC Kernel::Int32 kY = 10; +STATIC Kernel::Int32 kPrevX = 10; +STATIC Kernel::Int32 kPrevY = 10; +STATIC Kernel::Int32 kX = 10; +STATIC Kernel::Int32 kY = 10; STATIC Kernel::Int32 kMouseCycle = 0; STATIC Kernel::PS2MouseInterface kMousePS2; -STATIC Kernel::Char kMousePacket[4] = {}; +STATIC Kernel::Char kMousePacket[4] = {}; STATIC Kernel::Boolean kMousePacketReady = false; -STATIC GXInit(); +STATIC CGInit(); #define kPS2Leftbutton 0b00000001 #define kPS2Middlebutton 0b00000010 diff --git a/Kernel/HALKit/AMD64/HalPageAlloc.hpp b/Kernel/HALKit/AMD64/HalPageAlloc.hxx index 55193686..6e05e58e 100644 --- a/Kernel/HALKit/AMD64/HalPageAlloc.hpp +++ b/Kernel/HALKit/AMD64/HalPageAlloc.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -26,6 +26,10 @@ #define kPTESize (0x1000) #endif // !kPTESize +#ifndef kAlign +#define kAlign __BIGGEST_ALIGNMENT__ +#endif // !kAlign + EXTERN_C void hal_flush_tlb(); EXTERN_C void hal_write_cr3(Kernel::UIntPtr pde); EXTERN_C void hal_write_cr0(Kernel::UIntPtr bit); @@ -38,16 +42,16 @@ namespace Kernel::HAL { struct PACKED PageTable64 final { - bool Present : 1; - bool Rw : 1; - bool User : 1; - bool Wt : 1; - bool Cache : 1; - bool Accessed : 1; + bool Present : 1; + bool Rw : 1; + bool User : 1; + bool Wt : 1; + bool Cache : 1; + bool Accessed : 1; Kernel::Int32 Reserved : 6; Kernel::UInt64 PhysicalAddress : 36; Kernel::Int32 Reserved1 : 15; - bool ExecDisable : 1; + bool ExecDisable : 1; }; namespace Detail diff --git a/Kernel/HALKit/AMD64/HalProcessor.cpp b/Kernel/HALKit/AMD64/HalProcessor.cxx index 01f3879a..2eb2d693 100644 --- a/Kernel/HALKit/AMD64/HalProcessor.cpp +++ b/Kernel/HALKit/AMD64/HalProcessor.cxx @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <HALKit/AMD64/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> /** * @file Processor.cpp @@ -13,7 +13,7 @@ namespace Kernel::HAL { - void Out8(UInt16 port, UInt8 value) + Void Out8(UInt16 port, UInt8 value) { asm volatile("outb %%al, %1" : @@ -21,7 +21,7 @@ namespace Kernel::HAL : "memory"); } - void Out16(UInt16 port, UInt16 value) + Void Out16(UInt16 port, UInt16 value) { asm volatile("outw %%ax, %1" : @@ -29,7 +29,7 @@ namespace Kernel::HAL : "memory"); } - void Out32(UInt16 port, UInt32 value) + Void Out32(UInt16 port, UInt32 value) { asm volatile("outl %%eax, %1" : @@ -70,27 +70,27 @@ namespace Kernel::HAL return value; } - void rt_halt() + Void rt_halt() { asm volatile("hlt"); } - void rt_cli() + Void rt_cli() { asm volatile("cli"); } - void rt_sti() + Void rt_sti() { asm volatile("sti"); } - void rt_cld() + Void rt_cld() { asm volatile("cld"); } - void rt_std() + Void rt_std() { asm volatile("std"); } diff --git a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm index 7b0926bb..7f6aa26a 100644 --- a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm +++ b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm @@ -2,7 +2,7 @@ ;; * ======================================================== ;; * ;; * Kernel -;; * Copyright Zeta Electronics Corporation, all rights reserved. +;; * Copyright ZKA Technologies, all rights reserved. ;; * ;; * ======================================================== ;; */ diff --git a/Kernel/HALKit/AMD64/HalSMPCore.cxx b/Kernel/HALKit/AMD64/HalScheduler.cxx index 4cb87542..791361b5 100644 --- a/Kernel/HALKit/AMD64/HalSMPCore.cxx +++ b/Kernel/HALKit/AMD64/HalScheduler.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -12,8 +12,8 @@ Void ProcessHeader::SetEntrypoint(UIntPtr& imageStart) noexcept if (imageStart == 0) this->Crash(); - this->StackFrame->Rbp = imageStart; - this->StackFrame->Rsp = this->StackFrame->Rbp; + this->StackFrame->BP = imageStart; + this->StackFrame->SP = this->StackFrame->BP; } namespace Kernel @@ -22,7 +22,7 @@ namespace Kernel { if (!stackPtr) return false; - if (stackPtr->Rbp == 0 || stackPtr->Rsp == 0) + if (stackPtr->BP == 0 || stackPtr->SP == 0) return false; return true; diff --git a/Kernel/HALKit/AMD64/HalTimer.cxx b/Kernel/HALKit/AMD64/HalTimer.cxx index e69de29b..e893198f 100644 --- a/Kernel/HALKit/AMD64/HalTimer.cxx +++ b/Kernel/HALKit/AMD64/HalTimer.cxx @@ -0,0 +1,14 @@ +/* -------------------------------------------
+
+ Copyright ZKA Technologies
+
+ File: HalTimer.cxx
+ Purpose: HAL timer
+
+ Revision History:
+
+ 07/07/24: Added file (amlel)
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hpp>
\ No newline at end of file diff --git a/Kernel/HALKit/AMD64/HalUtils.asm b/Kernel/HALKit/AMD64/HalUtils.asm new file mode 100644 index 00000000..6681a692 --- /dev/null +++ b/Kernel/HALKit/AMD64/HalUtils.asm @@ -0,0 +1,49 @@ +;; /* +;; * ======================================================== +;; * +;; * Kernel +;; * Copyright ZKA Technologies, all rights reserved. +;; * +;; * ======================================================== +;; */ + +[bits 64] + +[global rt_install_tib] + +section .text + +;; changed: rs, fs +;; expected: rcx, rdx + +rt_install_tib: + mov rcx, gs ;; TIB -> Thread Information Block + mov rdx, fs ;; PIB -> Process Information Block + ret + +;; //////////////////////////////////////////////////// ;; + +[global rt_jump_user_mode] + +;; @used rcx, address to jump on. +;; @note adjusted for long mode. +rt_jump_user_mode: + cmp rcx, 0 + je rt_jump_user_mode_failed + + mov ax, (6 * 8) | 3 ; user data segment with RPL 3 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax ; SS is handled by iret + + mov rax, rsp + push (6 * 8) | 3 + push rax + pushf + push (5 * 8) | 3 ; user code segment with RPL 3 + push rcx + iretq + ;; we just failed to validate the rcx, fallback and return to previous pc. +rt_jump_user_mode_failed: + ret
\ No newline at end of file diff --git a/Kernel/HALKit/AMD64/Hypervisor.hpp b/Kernel/HALKit/AMD64/Hypervisor.hpp index 1ab69ef4..b5fe48c2 100644 --- a/Kernel/HALKit/AMD64/Hypervisor.hpp +++ b/Kernel/HALKit/AMD64/Hypervisor.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -21,6 +21,5 @@ namespace Kernel ENUM_STRING(ParallelsAlt, " lrpepyh vr "); ENUM_STRING(Bhyve, "bhyve bhyve "); ENUM_STRING(Qnx, " QNXQVMBSQG "); - END_STRING_ENUM() } // namespace Kernel diff --git a/Kernel/HALKit/AMD64/PCI/Database.cxx b/Kernel/HALKit/AMD64/PCI/Database.cxx index 65ec307e..67ebc6df 100644 --- a/Kernel/HALKit/AMD64/PCI/Database.cxx +++ b/Kernel/HALKit/AMD64/PCI/Database.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/AMD64/PCI/Device.cxx b/Kernel/HALKit/AMD64/PCI/Device.cxx index c1fdc401..bec401d9 100644 --- a/Kernel/HALKit/AMD64/PCI/Device.cxx +++ b/Kernel/HALKit/AMD64/PCI/Device.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -10,11 +10,11 @@ Kernel::UInt NewOSPCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun) { Kernel::UInt target = 0x80000000 | ((Kernel::UInt)bus << 16) | - ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) | - (bar & 0xFC); + ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) | + (bar & 0xFC); Kernel::HAL::Out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress, - target); + target); return Kernel::HAL::In32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigData); } @@ -22,11 +22,11 @@ Kernel::UInt NewOSPCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShor void NewOSPCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun) { Kernel::UInt target = 0x80000000 | ((Kernel::UInt)bus << 16) | - ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) | - (bar & ~3); + ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) | + (bar & ~3); Kernel::HAL::Out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress, - target); + target); } namespace Kernel::PCI diff --git a/Kernel/HALKit/AMD64/PCI/Dma.cxx b/Kernel/HALKit/AMD64/PCI/Dma.cxx index 3e6319e3..65bf7e72 100644 --- a/Kernel/HALKit/AMD64/PCI/Dma.cxx +++ b/Kernel/HALKit/AMD64/PCI/Dma.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/AMD64/PCI/Express.cxx b/Kernel/HALKit/AMD64/PCI/Express.cxx index 2b88f312..cb999fe0 100644 --- a/Kernel/HALKit/AMD64/PCI/Express.cxx +++ b/Kernel/HALKit/AMD64/PCI/Express.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/AMD64/PCI/IO.cxx b/Kernel/HALKit/AMD64/PCI/IO.cxx index 24ee05b3..8da2b21e 100644 --- a/Kernel/HALKit/AMD64/PCI/IO.cxx +++ b/Kernel/HALKit/AMD64/PCI/IO.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/AMD64/PCI/Iterator.cxx b/Kernel/HALKit/AMD64/PCI/Iterator.cxx index 0f766111..df593f7a 100644 --- a/Kernel/HALKit/AMD64/PCI/Iterator.cxx +++ b/Kernel/HALKit/AMD64/PCI/Iterator.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/AMD64/PCI/PCI.cxx b/Kernel/HALKit/AMD64/PCI/PCI.cxx index eaf7f20a..d15b1b9a 100644 --- a/Kernel/HALKit/AMD64/PCI/PCI.cxx +++ b/Kernel/HALKit/AMD64/PCI/PCI.cxx @@ -1,7 +1,7 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <KernelKit/PCI/PCI.hpp> +#include <KernelKit/PCI/PCI.hxx> diff --git a/Kernel/HALKit/AMD64/Processor.hpp b/Kernel/HALKit/AMD64/Processor.hxx index 756c5770..92b91c70 100644 --- a/Kernel/HALKit/AMD64/Processor.hpp +++ b/Kernel/HALKit/AMD64/Processor.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: Prcoessor.hxx Purpose: AMD64 processor abstraction. @@ -17,7 +17,12 @@ #include <NewKit/Defines.hpp> #include <NewKit/Utils.hpp> #include <FirmwareKit/Handover.hxx> -#include <HALKit/AMD64/HalPageAlloc.hpp> +#include <HALKit/AMD64/HalPageAlloc.hxx> + +EXTERN_C +{ +#include <cpuid.h> +} #ifdef kCPUBackendName #undef kCPUBackendName @@ -25,6 +30,8 @@ #define kCPUBackendName "AMD64" +#define kSyscallRoute 0x32 + #define IsActiveLow(FLG) (FLG & 2) #define IsLevelTriggered(FLG) (FLG & 8) @@ -32,6 +39,7 @@ #define kTrapGate (0xEF) #define kTaskGate (0b10001100) #define kGdtCodeSelector (0x08) +#define kGdtUserCodeSelector (0x10) #define cHeapStartOffset (0x10000000) namespace Kernel @@ -71,16 +79,17 @@ namespace Kernel::HAL { UInt16 pml4_index = (virt_addr >> 39) & 0x1FF; - if (!pde->Pte[pml4_index].Present) + if (pde && !pde->Pte[pml4_index].Present) { pde->Pte[pml4_index].Present = true; - kcout << "PM is present now.\r"; pde->Pte[pml4_index].PhysicalAddress = phys_addr; pde->Pte[pml4_index].Rw = flags & eFlagsRw; pde->Pte[pml4_index].User = flags & eFlagsUser; pde->Pte[pml4_index].ExecDisable = flags & eFlagsExecDisable; + kcout << "PTE is present now.\r"; + return 0; } else @@ -90,13 +99,13 @@ namespace Kernel::HAL kcout << "PhysicalAddress: " << hex_number(pde->Pte[pml4_index].PhysicalAddress); kcout << "\r"; - kcout << "User: " << (pde->Pte[pml4_index].User ? "YES" : "NO") << "\r"; - kcout << "RW: " << (pde->Pte[pml4_index].Rw ? "YES" : "NO") << "\r"; + kcout << "User: " << (pde->Pte[pml4_index].User ? "true" : "false") << "\r"; + kcout << "RW: " << (pde->Pte[pml4_index].Rw ? "true" : "false") << "\r"; - return 1; + return 0; } - return 0; + return 1; } /// @brief Map address to PDE. @@ -104,7 +113,7 @@ namespace Kernel::HAL /// @param phys_addr /// @param virt_addr /// @param flags - inline void ke_unmap_address(PDE* pde, UIntPtr phys_addr, UIntPtr virt_addr, UInt32 flags) + inline Void ke_unmap_address(PDE* pde, UIntPtr phys_addr, UIntPtr virt_addr, UInt32 flags) { UInt16 pml4_index = (virt_addr >> 39) & 0x1FF; @@ -152,10 +161,11 @@ namespace Kernel::HAL typedef UIntPtr Reg; + /// @brief Stack frame (as retrieved from assembly.) struct PACKED StackFrame final { Reg IntNum, Exception; - Reg Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax; + Reg A0, A2, BP, SP, A3, A4, A5, A6; Reg R8, R9, R10, R11, R12, R13, R14, R15; Reg Gs, Fs; }; @@ -200,11 +210,12 @@ namespace Kernel::HAL class SegmentDescriptorComparator final { public: - bool IsValid(SegmentDescriptor& seg) + Bool IsValid(SegmentDescriptor& seg) { return seg.Base > seg.Limit; } - bool Equals(SegmentDescriptor& seg, SegmentDescriptor& segRight) + + Bool Equals(SegmentDescriptor& seg, SegmentDescriptor& segRight) { return seg.Base == segRight.Base && seg.Limit == segRight.Limit; } @@ -215,29 +226,65 @@ namespace Kernel::HAL class GDTLoader final { public: - static void Load(RegisterGDT& gdt); - static void Load(Ref<RegisterGDT>& gdt); + static Void Load(RegisterGDT& gdt); + static Void Load(Ref<RegisterGDT>& gdt); }; class IDTLoader final { public: - static void Load(Register64& idt); - static void Load(Ref<Register64>& idt); + static Void Load(Register64& idt); + static Void Load(Ref<Register64>& idt); }; Void hal_system_get_cores(VoidPtr rsdPtr); Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress); Void hal_send_end_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress); - /// @brief Processor specific structures. - namespace Detail + /// @brief Do a cpuid to check if MSR exists on CPU. + /// @retval true it does exists. + /// @retval false it doesn't. + inline Bool hal_has_msr() noexcept + { + static UInt32 eax, unused, edx; // eax, edx + + __get_cpuid(1, &eax, &unused, &unused, &edx); + + // edx returns the flag for MSR (which is 1 shifted to 5.) + return edx & (1 << 5); + } + + /// @brief Get Model-specific register. + /// @param msr MSR + /// @param lo low byte + /// @param hi high byte + inline Void hal_get_msr(UInt32 msr, UInt32* lo, UInt32* hi) noexcept + { + if (!lo || !hi) + return; + + asm volatile("rdmsr" + : "=a"(*lo), "=d"(*hi) + : "c"(msr)); + } + + /// @brief Set Model-specific register. + /// @param msr MSR + /// @param lo low byte + /// @param hi high byte + inline Void hal_set_msr(UInt32 msr, UInt32 lo, UInt32 hi) noexcept { - EXTERN_C void _ke_power_on_self_test(void); + asm volatile("wrmsr" + : + : "a"(lo), "d"(hi), "c"(msr)); + } + /// @brief Processor specific namespace. + namespace Detail + { /** - @brief Global descriptor table entry, either null, code or data. -*/ + @brief Global descriptor table entry, either null, code or data. + */ struct PACKED NewOSGDTRecord final { @@ -259,15 +306,35 @@ namespace Kernel::HAL NewOSGDTRecord UserData; }; } // namespace Detail + + class APICController + { + public: + explicit APICController(VoidPtr base) + : fApic(base) + { + } + + ~APICController() = default; + + NEWOS_COPY_DEFAULT(APICController); + + public: + UInt32 Read(UInt32 reg) noexcept; + Void Write(UInt32 reg, UInt32 value) noexcept; + + private: + VoidPtr fApic{nullptr}; + }; } // namespace Kernel::HAL -EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp); -EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp); -EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp); -EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp); +EXTERN_C Kernel::Void idt_handle_generic(Kernel::UIntPtr rsp); +EXTERN_C Kernel::Void idt_handle_gpf(Kernel::UIntPtr rsp); +EXTERN_C Kernel::Void idt_handle_math(Kernel::UIntPtr rsp); +EXTERN_C Kernel::Void idt_handle_pf(Kernel::UIntPtr rsp); -EXTERN_C void hal_load_idt(Kernel::HAL::Register64 ptr); -EXTERN_C void hal_load_gdt(Kernel::HAL::RegisterGDT ptr); +EXTERN_C Kernel::Void hal_load_idt(Kernel::HAL::Register64 ptr); +EXTERN_C Kernel::Void hal_load_gdt(Kernel::HAL::RegisterGDT ptr); /// @brief Maximum size of the IDT. #define kKernelIdtSize 0x100 diff --git a/Kernel/HALKit/AMD64/Storage/AHCI.cxx b/Kernel/HALKit/AMD64/Storage/AHCI.cxx index 51153417..7a83b836 100644 --- a/Kernel/HALKit/AMD64/Storage/AHCI.cxx +++ b/Kernel/HALKit/AMD64/Storage/AHCI.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -11,7 +11,7 @@ * @version 0.1 * @date 2024-02-02 * - * @copyright Copyright (c) Zeta Electronics Corporation + * @copyright Copyright (c) ZKA Technologies * */ diff --git a/Kernel/HALKit/AMD64/Storage/ATA-DMA.cxx b/Kernel/HALKit/AMD64/Storage/ATA-DMA.cxx index 33e6bc31..bcba23e1 100644 --- a/Kernel/HALKit/AMD64/Storage/ATA-DMA.cxx +++ b/Kernel/HALKit/AMD64/Storage/ATA-DMA.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -11,7 +11,7 @@ * @version 0.1 * @date 2024-02-02 * - * @copyright Copyright (c) Zeta Electronics Corporation + * @copyright Copyright (c) ZKA Technologies * */ diff --git a/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx b/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx index 1a8e78c3..fa64294d 100644 --- a/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx +++ b/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -11,7 +11,7 @@ * @version 0.1 * @date 2024-02-02 * - * @copyright Copyright (c) Zeta Electronics Corporation + * @copyright Copyright (c) ZKA Technologies * */ diff --git a/Kernel/HALKit/ARM64/HalHart.cxx b/Kernel/HALKit/ARM64/HalHart.cxx new file mode 100644 index 00000000..d7a34505 --- /dev/null +++ b/Kernel/HALKit/ARM64/HalHart.cxx @@ -0,0 +1,29 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#include <ArchKit/ArchKit.hpp> + +// bugs = 0 + +namespace Kernel +{ + /// @brief wakes up thread. + /// wakes up thread from hang. + void rt_wakeup_thread(HAL::StackFrame* stack) + { + rt_do_context_switch(stack); + } + + /// @brief makes the thread sleep on a loop. + /// hooks and hangs thread to prevent code from executing. + void rt_hang_thread(HAL::StackFrame* stack) + { + while (true) + { + /* nohing, code is spinning */ + } + } +} // namespace Kernel diff --git a/Kernel/HALKit/ARM64/HalKernelMain.cxx b/Kernel/HALKit/ARM64/HalKernelMain.cxx new file mode 100644 index 00000000..a2d215f6 --- /dev/null +++ b/Kernel/HALKit/ARM64/HalKernelMain.cxx @@ -0,0 +1,178 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#include <ArchKit/ArchKit.hpp> +#include <Modules/CoreCG/CoreCG.hxx> +#include <FirmwareKit/Handover.hxx> +#include <KernelKit/FileManager.hpp> +#include <KernelKit/Framebuffer.hpp> +#include <KernelKit/Heap.hxx> +#include <KernelKit/PEFCodeManager.hxx> +#include <KernelKit/ProcessScheduler.hxx> +#include <KernelKit/ProcessHeap.hxx> +#include <NewKit/Json.hxx> +#include <Modules/CoreCG/Accessibility.hxx> +#include <KernelKit/CodeManager.hpp> +#include <Modules/ACPI/ACPIFactoryInterface.hxx> +#include <NetworkKit/IPCEP.hxx> + +#define KERNEL_INIT(X) \ + X; \ + Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP); + +/// @brief This symbol is the kernel main symbol. +EXTERN_C void KeMain(); + +EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; + +struct PACKED HeapAllocInfo final +{ + Kernel::VoidPtr fThe; + Kernel::Size fTheSz; +}; + +struct PACKED ProcessBlockInfo final +{ + ThreadInformationBlock* fTIB; + ThreadInformationBlock* fPIB; +}; + +struct PACKED ProcessExitInfo final +{ + STATIC constexpr auto cReasonLen = 512; + + Kernel::Int64 fCode; + Kernel::Char fReason[cReasonLen]; +}; + +EXTERN_C void hal_init_platform( + Kernel::HEL::HandoverInformationHeader* HandoverHeader) +{ + /* Setup globals. */ + + kHandoverHeader = HandoverHeader; + + if (kHandoverHeader->f_Magic != kHandoverMagic && + kHandoverHeader->f_Version != kHandoverVersion) + { + return; + } + + kKernelVirtualSize = HandoverHeader->f_VirtualSize; + kKernelVirtualStart = reinterpret_cast<Kernel::VoidPtr>( + reinterpret_cast<Kernel::UIntPtr>(HandoverHeader->f_VirtualStart) + cHeapStartOffset); + + kKernelPhysicalStart = HandoverHeader->f_PhysicalStart; + + // Register the basic SCI functions. + + constexpr auto cSerialAlertInterrupt = 0x10; + constexpr auto cTlsInterrupt = 0x11; + constexpr auto cTlsInstallInterrupt = 0x12; + constexpr auto cNewInterrupt = 0x13; + constexpr auto cDeleteInterrupt = 0x14; + constexpr auto cExitInterrupt = 0x15; + constexpr auto cLastExitInterrupt = 0x16; + constexpr auto cCatalogOpen = 0x17; + constexpr auto cForkRead = 0x18; + constexpr auto cForkWrite = 0x19; + constexpr auto cCatalogClose = 0x20; + constexpr auto cCatalogRemove = 0x21; + constexpr auto cCatalogCreate = 0x22; + constexpr auto cRebootInterrupt = 0x23; + constexpr auto cShutdownInterrupt = 0x24; + constexpr auto cLPCSendMsg = 0x25; + constexpr auto cLPCOpenMsg = 0x26; + constexpr auto cLPCCloseMsg = 0x27; + constexpr auto cLPCSanitizeMsg = 0x28; + + kSyscalls[cSerialAlertInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { + const char* msg = (const char*)rdx; + Kernel::kcout << "serial: " << msg << "\r"; + }; + + kSyscalls[cTlsInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { + tls_check_syscall_impl(rdx); + }; + + kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { + Kernel::ipc_sanitize_packet(reinterpret_cast<Kernel::IPCEPMessageHeader*>(rdx)); + }; + + kSyscalls[cNewInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { + // get HAC struct. + HeapAllocInfo* rdxInf = reinterpret_cast<HeapAllocInfo*>(rdx); + + if (!rdxInf) + return; + + // assign the fThe field with the pointer. + rdxInf->fThe = Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().New(rdxInf->fTheSz); + }; + + kSyscalls[cDeleteInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { + // get HAC struct. + HeapAllocInfo* rdxInf = reinterpret_cast<HeapAllocInfo*>(rdx); + + if (!rdxInf) + return; + + // delete ptr with sz in mind. + Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Delete(rdxInf->fThe, rdxInf->fTheSz); + }; + + kSyscalls[cTlsInstallInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { + ProcessBlockInfo* rdxPb = reinterpret_cast<ProcessBlockInfo*>(rdx); + + if (!rdxPb) + return; + + // install the fTIB and fPIB. + rt_install_tib(rdxPb->fTIB, rdxPb->fPIB); + }; + + kSyscalls[cExitInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { + ProcessExitInfo* rdxEi = reinterpret_cast<ProcessExitInfo*>(rdx); + + if (!rdxEi) + return; + + Kernel::kcout << "newoskrnl: " << rdxEi->fReason << "\r"; + Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Exit(rdxEi->fCode); + }; + + kSyscalls[cLastExitInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { + ProcessExitInfo* rdxEi = reinterpret_cast<ProcessExitInfo*>(rdx); + + if (!rdxEi) + return; + + rdxEi->fCode = Kernel::rt_get_exit_code(); + }; + + kSyscalls[cRebootInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { + Kernel::ACPIFactoryInterface acpi(kHandoverHeader->f_HardwareTables.f_VendorPtr); + acpi.Reboot(); + }; + + kSyscalls[cShutdownInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { + Kernel::ACPIFactoryInterface acpi(kHandoverHeader->f_HardwareTables.f_VendorPtr); + acpi.Shutdown(); + }; + + kSyscalls[cSerialAlertInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cTlsInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cTlsInstallInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cDeleteInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cNewInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cExitInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cLastExitInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cShutdownInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cRebootInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fHooked = true; + + KERNEL_INIT(KeMain()); +} diff --git a/Kernel/HALKit/ARM64/HalPageAlloc.hpp b/Kernel/HALKit/ARM64/HalPageAlloc.hxx index 8286b5cd..7e34dc75 100644 --- a/Kernel/HALKit/ARM64/HalPageAlloc.hpp +++ b/Kernel/HALKit/ARM64/HalPageAlloc.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/ARM64/HalScheduler.cxx b/Kernel/HALKit/ARM64/HalScheduler.cxx new file mode 100644 index 00000000..08703435 --- /dev/null +++ b/Kernel/HALKit/ARM64/HalScheduler.cxx @@ -0,0 +1,31 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#include <KernelKit/ProcessScheduler.hxx> + +using namespace Kernel; + +Void ProcessHeader::SetEntrypoint(UIntPtr& imageStart) noexcept +{ + if (imageStart == 0) + this->Crash(); + + this->StackFrame->BP = imageStart; + this->StackFrame->SP = this->StackFrame->BP; +} + +namespace Kernel +{ + bool rt_check_stack(HAL::StackFramePtr stackPtr) + { + if (!stackPtr) + return false; + if (stackPtr->BP == 0 || stackPtr->SP == 0) + return false; + + return true; + } +} // namespace Kernel diff --git a/Kernel/HALKit/ARM64/HalTimer.cxx b/Kernel/HALKit/ARM64/HalTimer.cxx index aa39adef..63e924c3 100644 --- a/Kernel/HALKit/ARM64/HalTimer.cxx +++ b/Kernel/HALKit/ARM64/HalTimer.cxx @@ -1,7 +1,16 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies + + File: HalTimer.cxx + Purpose: HAL timer + + Revision History: + + 07/07/24: Added file (amlel) ------------------------------------------- */ -#include <NewKit/Defines.hpp> +#include <ArchKit/ArchKit.hpp> + +struct TimerInfoStruct; diff --git a/Kernel/HALKit/ARM64/Processor.hxx b/Kernel/HALKit/ARM64/Processor.hxx index 631ecdf0..63c73972 100644 --- a/Kernel/HALKit/ARM64/Processor.hxx +++ b/Kernel/HALKit/ARM64/Processor.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -36,10 +36,11 @@ namespace Kernel::HAL typedef UIntPtr Reg; typedef Register64 Register; + /// @note let's keep the same name as AMD64 HAL. struct PACKED StackFrame final { Reg IntNum, Exception; - Reg Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax; + Reg A0, A2, BP, SP, A3, A4, A5, A6; Reg R8, R9, R10, R11, R12, R13, R14, R15; Reg Gs, Fs; }; @@ -52,4 +53,4 @@ inline Kernel::UIntPtr kKernelVirtualSize = 0UL; inline Kernel::VoidPtr kKernelPhysicalStart = nullptr; -#include <HALKit/ARM64/HalPageAlloc.hpp> +#include <HALKit/ARM64/HalPageAlloc.hxx> diff --git a/Kernel/HALKit/ARM64/ReadMe.md b/Kernel/HALKit/ARM64/ReadMe.md index d4d35a0b..c51229f2 100644 --- a/Kernel/HALKit/ARM64/ReadMe.md +++ b/Kernel/HALKit/ARM64/ReadMe.md @@ -1,3 +1,3 @@ # ARM64 Hardware Abstraction Layer -- Supported Firmware: CoreBoot
\ No newline at end of file +- Supported Firmware: CoreBoot/EDK/OpenMobileBoot diff --git a/Kernel/HALKit/ARM64/Storage/HalFlash.cxx b/Kernel/HALKit/ARM64/Storage/HalFlash.cxx index 20c2836d..ca2d4883 100644 --- a/Kernel/HALKit/ARM64/Storage/HalFlash.cxx +++ b/Kernel/HALKit/ARM64/Storage/HalFlash.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp index 4469eee9..579af6b5 100644 --- a/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp +++ b/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp @@ -1,11 +1,11 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <ArchKit/ArchKit.hpp> -#include <HALKit/AXP/Processor.hpp> +#include <HALKit/AXP/Processor.hxx> /// @brief Internal call for syscall, to work with C++. /// @param stack diff --git a/Kernel/HALKit/AXP/Processor.hpp b/Kernel/HALKit/AXP/Processor.hpp index a3799ae7..a244ff91 100644 --- a/Kernel/HALKit/AXP/Processor.hpp +++ b/Kernel/HALKit/AXP/Processor.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/POWER/HalContextSwitchPowerPC.s b/Kernel/HALKit/POWER/HalContextSwitchPowerPC.s index 14d805db..e14efb6b 100644 --- a/Kernel/HALKit/POWER/HalContextSwitchPowerPC.s +++ b/Kernel/HALKit/POWER/HalContextSwitchPowerPC.s @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/POWER/HalHardware.cxx b/Kernel/HALKit/POWER/HalHardware.cxx index 15407eb3..a057355e 100644 --- a/Kernel/HALKit/POWER/HalHardware.cxx +++ b/Kernel/HALKit/POWER/HalHardware.cxx @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> namespace Kernel diff --git a/Kernel/HALKit/POWER/HalHart.cxx b/Kernel/HALKit/POWER/HalHart.cxx index 614828cb..5ff12218 100644 --- a/Kernel/HALKit/POWER/HalHart.cxx +++ b/Kernel/HALKit/POWER/HalHart.cxx @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> #include <HALKit/POWER/Hart.hxx> diff --git a/Kernel/HALKit/POWER/HalSerialPort.cxx b/Kernel/HALKit/POWER/HalSerialPort.cxx index abddd291..86b43bb7 100644 --- a/Kernel/HALKit/POWER/HalSerialPort.cxx +++ b/Kernel/HALKit/POWER/HalSerialPort.cxx @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> using namespace Kernel; @@ -17,7 +17,7 @@ void ke_io_write(const Char* bytes) return; SizeT index = 0; - SizeT len = rt_string_len(bytes, 256); + SizeT len = rt_string_len(bytes, 255); while (index < len) { diff --git a/Kernel/HALKit/POWER/HalStartSequence.s b/Kernel/HALKit/POWER/HalStartSequence.s index 07cec350..a2741103 100644 --- a/Kernel/HALKit/POWER/HalStartSequence.s +++ b/Kernel/HALKit/POWER/HalStartSequence.s @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/HALKit/POWER/HalThread.cxx b/Kernel/HALKit/POWER/HalThread.cxx index 18d84d4f..b3be23c4 100644 --- a/Kernel/HALKit/POWER/HalThread.cxx +++ b/Kernel/HALKit/POWER/HalThread.cxx @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> EXTERN_C Kernel::HAL::StackFramePtr rt_get_current_context() diff --git a/Kernel/HALKit/POWER/HalVirtualMemory.cxx b/Kernel/HALKit/POWER/HalVirtualMemory.cxx index eb04a43d..039bf509 100644 --- a/Kernel/HALKit/POWER/HalVirtualMemory.cxx +++ b/Kernel/HALKit/POWER/HalVirtualMemory.cxx @@ -1,26 +1,20 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <HALKit/POWER/ppc-cpu.h> #include <HALKit/POWER/ppc-mmu.h> -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> -/// @note refer to our SoC documentation. +/// @note refer to the SoC documentation. using namespace Kernel; -/// @brief Write directly to the specific TLB. -/// @param mas0 -/// @param mas1 -/// @param mas2 -/// @param mas3 -/// @param mas7 -static void hal_write_tlb(uint32_t mas0, uint32_t mas1, uint32_t mas2, uint32_t mas3, uint32_t mas7) +Void hal_write_tlb(UInt32 mas0, UInt32 mas1, UInt32 mas2, UInt32 mas3, UInt32 mas7) { mtspr(MAS0, mas0); mtspr(MAS1, mas1); @@ -31,23 +25,26 @@ static void hal_write_tlb(uint32_t mas0, uint32_t mas1, uint32_t mas2, uint32_t hal_flush_tlb(); } -void hal_set_tlb(uint8_t tlb, uint32_t epn, uint64_t rpn, uint8_t perms, uint8_t wimge, uint8_t ts, uint8_t esel, uint8_t tsize, uint8_t iprot) +Bool hal_set_tlb(UInt8 tlb, UInt32 epn, UInt64 rpn, UInt8 perms, UInt8 wimge, UInt8 ts, UInt8 esel, UInt8 tsize, UInt8 iprot) { if ((mfspr(SPRN_MMUCFG) & MMUCFG_MAVN) == MMUCFG_MAVN_V1 && (tsize & 1)) { // this mmu-version does not allow odd tsize values - return; + return false; } - uint32_t mas0 = FSL_BOOKE_MAS0(tlb, esel, 0); - uint32_t mas1 = FSL_BOOKE_MAS1(1, iprot, 0, ts, tsize); - uint32_t mas2 = FSL_BOOKE_MAS2(epn, wimge); - uint32_t mas3 = FSL_BOOKE_MAS3(rpn, 0, perms); - uint32_t mas7 = FSL_BOOKE_MAS7(rpn); + + UInt32 mas0 = FSL_BOOKE_MAS0(tlb, esel, 0); + UInt32 mas1 = FSL_BOOKE_MAS1(1, iprot, 0, ts, tsize); + UInt32 mas2 = FSL_BOOKE_MAS2(epn, wimge); + UInt32 mas3 = FSL_BOOKE_MAS3(rpn, 0, perms); + UInt32 mas7 = FSL_BOOKE_MAS7(rpn); hal_write_tlb(mas0, mas1, mas2, mas3, mas7); + + return true; } -/// @brief Flush system TLB. +/// @brief Flush TLB EXTERN_C void hal_flush_tlb() { asm volatile("isync;tlbwe;msync;isync"); diff --git a/Kernel/HALKit/POWER/Hart.hxx b/Kernel/HALKit/POWER/Hart.hxx index 8f466098..e887ce4a 100644 --- a/Kernel/HALKit/POWER/Hart.hxx +++ b/Kernel/HALKit/POWER/Hart.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: Hart.hxx Purpose: POWER hardware threads. @@ -22,9 +22,9 @@ typedef Kernel::Int32 PPCHartType; typedef struct HalHardwareThread { Kernel::UIntPtr fStartAddress; - Kernel::UInt8 fPrivleged : 1; - Kernel::UInt32 fPageFlags; - PPCHartType fIdentNumber; + Kernel::UInt8 fPrivleged : 1; + Kernel::UInt32 fPageFlags; + PPCHartType fIdentNumber; } HalHardwareThread; /// @brief Set PC to specific hart. diff --git a/Kernel/HALKit/POWER/MBCI/HalMBCIHost.cxx b/Kernel/HALKit/POWER/MBCI/HalMBCIHost.cxx index 8a24506a..93cf86ae 100644 --- a/Kernel/HALKit/POWER/MBCI/HalMBCIHost.cxx +++ b/Kernel/HALKit/POWER/MBCI/HalMBCIHost.cxx @@ -1,8 +1,8 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> diff --git a/Kernel/HALKit/POWER/Processor.hpp b/Kernel/HALKit/POWER/Processor.hpp deleted file mode 100644 index 5ff7eef3..00000000 --- a/Kernel/HALKit/POWER/Processor.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - - Purpose: POWER processor header. - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Defines.hpp> -#include <NewKit/Utils.hpp> - -#define kHalPPCAlignment __attribute__((aligned(4))) - -namespace Kernel::HAL -{ - typedef UIntPtr Reg; - - struct kHalPPCAlignment StackFrame - { - Reg R0; - Reg R1; - Reg R2; - Reg R3; - Reg R4; - Reg R5; - Reg R6; - Reg R7; - Reg R8; - Reg PC; - Reg SP; - }; - - typedef StackFrame* StackFramePtr; - - inline void rt_halt() - { - while (1) - { - asm volatile("mr 0, 0"); // no oop. - } - } - - inline void rt_cli() - { - asm volatile("mr 0, 0"); // no oop - } -} // namespace Kernel::HAL - -EXTERN_C void int_handle_math(Kernel::UIntPtr sp); -EXTERN_C void int_handle_pf(Kernel::UIntPtr sp); - -/// @brief Flush system TLB. -EXTERN_C void hal_flush_tlb(); diff --git a/Kernel/HALKit/POWER/Processor.hxx b/Kernel/HALKit/POWER/Processor.hxx new file mode 100644 index 00000000..b2186aa7 --- /dev/null +++ b/Kernel/HALKit/POWER/Processor.hxx @@ -0,0 +1,56 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + + Purpose: POWER processor header. + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Defines.hpp> +#include <NewKit/Utils.hpp> + +#define NoOp() asm volatile("mr 0, 0") +#define kHalPPCAlignment __attribute__((aligned(4))) + +namespace Kernel::HAL +{ + typedef UIntPtr Reg; + + /// @brief Stack frame (as retrieved from assembly.) + struct PACKED StackFrame final + { + Reg IntNum, Exception; + Reg A0, A2, BP, SP, A3, A4, A5, A6; + Reg R8, R9, R10, R11, R12, R13, R14, R15; + Reg Gs, Fs; + }; + + typedef StackFrame* StackFramePtr; + + inline void rt_halt() + { + while (true) + { + NoOp(); // no oop. + } + } + + inline void rt_cli() + { + NoOp(); // no oop + } +} // namespace Kernel::HAL + +EXTERN_C Kernel::Void int_handle_math(Kernel::UIntPtr sp); +EXTERN_C Kernel::Void int_handle_pf(Kernel::UIntPtr sp); + +/// @brief Set TLB. +Kernel::Bool hal_set_tlb(Kernel::UInt8 tlb, Kernel::UInt32 epn, Kernel::UInt64 rpn, Kernel::UInt8 perms, Kernel::UInt8 wimge, Kernel::UInt8 ts, Kernel::UInt8 esel, Kernel::UInt8 tsize, Kernel::UInt8 iprot); + +/// @brief Write TLB. +Kernel::Void hal_write_tlb(Kernel::UInt32 mas0, Kernel::UInt32 mas1, Kernel::UInt32 mas2, Kernel::UInt32 mas3, Kernel::UInt32 mas7); + +/// @brief Flush TLB. +EXTERN_C Kernel::Void hal_flush_tlb(); diff --git a/Kernel/HALKit/POWER/ppc-cpu.h b/Kernel/HALKit/POWER/ppc-cpu.h index 3855b85c..46979e5f 100644 --- a/Kernel/HALKit/POWER/ppc-cpu.h +++ b/Kernel/HALKit/POWER/ppc-cpu.h @@ -141,36 +141,36 @@ struct pt_regs #define SPRN_DBCR 0x3F2 /* Debug Control Regsiter */ #define DBCR_EDM 0x80000000 #define DBCR_IDM 0x40000000 -#define DBCR_RST(x) (((x)&0x3) << 28) +#define DBCR_RST(x) (((x) & 0x3) << 28) #define DBCR_RST_NONE 0 #define DBCR_RST_CORE 1 #define DBCR_RST_CHIP 2 #define DBCR_RST_SYSTEM 3 -#define DBCR_IC 0x08000000 /* Instruction Completion Debug Evnt */ -#define DBCR_BT 0x04000000 /* Branch Taken Debug Event */ -#define DBCR_EDE 0x02000000 /* Exception Debug Event */ -#define DBCR_TDE 0x01000000 /* TRAP Debug Event */ -#define DBCR_FER 0x00F80000 /* First Events Remaining Mask */ -#define DBCR_FT 0x00040000 /* Freeze Timers on Debug Event */ -#define DBCR_IA1 0x00020000 /* Instr. Addr. Compare 1 Enable */ -#define DBCR_IA2 0x00010000 /* Instr. Addr. Compare 2 Enable */ -#define DBCR_D1R 0x00008000 /* Data Addr. Compare 1 Read Enable */ -#define DBCR_D1W 0x00004000 /* Data Addr. Compare 1 Write Enable */ -#define DBCR_D1S(x) (((x)&0x3) << 12) /* Data Adrr. Compare 1 Size */ +#define DBCR_IC 0x08000000 /* Instruction Completion Debug Evnt */ +#define DBCR_BT 0x04000000 /* Branch Taken Debug Event */ +#define DBCR_EDE 0x02000000 /* Exception Debug Event */ +#define DBCR_TDE 0x01000000 /* TRAP Debug Event */ +#define DBCR_FER 0x00F80000 /* First Events Remaining Mask */ +#define DBCR_FT 0x00040000 /* Freeze Timers on Debug Event */ +#define DBCR_IA1 0x00020000 /* Instr. Addr. Compare 1 Enable */ +#define DBCR_IA2 0x00010000 /* Instr. Addr. Compare 2 Enable */ +#define DBCR_D1R 0x00008000 /* Data Addr. Compare 1 Read Enable */ +#define DBCR_D1W 0x00004000 /* Data Addr. Compare 1 Write Enable */ +#define DBCR_D1S(x) (((x) & 0x3) << 12) /* Data Adrr. Compare 1 Size */ #define DAC_BYTE 0 #define DAC_HALF 1 #define DAC_WORD 2 #define DAC_QUAD 3 -#define DBCR_D2R 0x00000800 /* Data Addr. Compare 2 Read Enable */ -#define DBCR_D2W 0x00000400 /* Data Addr. Compare 2 Write Enable */ -#define DBCR_D2S(x) (((x)&0x3) << 8) /* Data Addr. Compare 2 Size */ -#define DBCR_SBT 0x00000040 /* Second Branch Taken Debug Event */ -#define DBCR_SED 0x00000020 /* Second Exception Debug Event */ -#define DBCR_STD 0x00000010 /* Second Trap Debug Event */ -#define DBCR_SIA 0x00000008 /* Second IAC Enable */ -#define DBCR_SDA 0x00000004 /* Second DAC Enable */ -#define DBCR_JOI 0x00000002 /* JTAG Serial Outbound Int. Enable */ -#define DBCR_JII 0x00000001 /* JTAG Serial Inbound Int. Enable */ +#define DBCR_D2R 0x00000800 /* Data Addr. Compare 2 Read Enable */ +#define DBCR_D2W 0x00000400 /* Data Addr. Compare 2 Write Enable */ +#define DBCR_D2S(x) (((x) & 0x3) << 8) /* Data Addr. Compare 2 Size */ +#define DBCR_SBT 0x00000040 /* Second Branch Taken Debug Event */ +#define DBCR_SED 0x00000020 /* Second Exception Debug Event */ +#define DBCR_STD 0x00000010 /* Second Trap Debug Event */ +#define DBCR_SIA 0x00000008 /* Second IAC Enable */ +#define DBCR_SDA 0x00000004 /* Second DAC Enable */ +#define DBCR_JOI 0x00000002 /* JTAG Serial Outbound Int. Enable */ +#define DBCR_JII 0x00000001 /* JTAG Serial Inbound Int. Enable */ #ifndef CONFIG_BOOKE #define SPRN_DBCR0 0x3F2 /* Debug Control Register 0 */ #else @@ -395,27 +395,27 @@ struct pt_regs #define TCR_WP(x) (((64 - x) & 0x3) << 30) | \ (((64 - x) & 0x3c) << 15) /* WDT Period 2^x clocks*/ #else -#define TCR_WP(x) (((x)&0x3) << 30) /* WDT Period */ -#define WP_2_17 0 /* 2^17 clocks */ -#define WP_2_21 1 /* 2^21 clocks */ -#define WP_2_25 2 /* 2^25 clocks */ -#define WP_2_29 3 /* 2^29 clocks */ -#endif /* CONFIG_E500 */ -#define TCR_WRC(x) (((x)&0x3) << 28) /* WDT Reset Control */ -#define WRC_NONE 0 /* No reset will occur */ -#define WRC_CORE 1 /* Core reset will occur */ -#define WRC_CHIP 2 /* Chip reset will occur */ -#define WRC_SYSTEM 3 /* System reset will occur */ -#define TCR_WIE 0x08000000 /* WDT Interrupt Enable */ -#define TCR_PIE 0x04000000 /* PIT Interrupt Enable */ -#define TCR_FP(x) (((x)&0x3) << 24) /* FIT Period */ -#define FP_2_9 0 /* 2^9 clocks */ -#define FP_2_13 1 /* 2^13 clocks */ -#define FP_2_17 2 /* 2^17 clocks */ -#define FP_2_21 3 /* 2^21 clocks */ -#define TCR_FIE 0x00800000 /* FIT Interrupt Enable */ -#define TCR_ARE 0x00400000 /* Auto Reload Enable */ -#define SPRN_THRM1 0x3FC /* Thermal Management Register 1 */ +#define TCR_WP(x) (((x) & 0x3) << 30) /* WDT Period */ +#define WP_2_17 0 /* 2^17 clocks */ +#define WP_2_21 1 /* 2^21 clocks */ +#define WP_2_25 2 /* 2^25 clocks */ +#define WP_2_29 3 /* 2^29 clocks */ +#endif /* CONFIG_E500 */ +#define TCR_WRC(x) (((x) & 0x3) << 28) /* WDT Reset Control */ +#define WRC_NONE 0 /* No reset will occur */ +#define WRC_CORE 1 /* Core reset will occur */ +#define WRC_CHIP 2 /* Chip reset will occur */ +#define WRC_SYSTEM 3 /* System reset will occur */ +#define TCR_WIE 0x08000000 /* WDT Interrupt Enable */ +#define TCR_PIE 0x04000000 /* PIT Interrupt Enable */ +#define TCR_FP(x) (((x) & 0x3) << 24) /* FIT Period */ +#define FP_2_9 0 /* 2^9 clocks */ +#define FP_2_13 1 /* 2^13 clocks */ +#define FP_2_17 2 /* 2^17 clocks */ +#define FP_2_21 3 /* 2^21 clocks */ +#define TCR_FIE 0x00800000 /* FIT Interrupt Enable */ +#define TCR_ARE 0x00400000 /* Auto Reload Enable */ +#define SPRN_THRM1 0x3FC /* Thermal Management Register 1 */ #define THRM1_TIN (1 << 0) #define THRM1_TIV (1 << 1) #define THRM1_THRES (0x7f << 2) @@ -429,26 +429,26 @@ struct pt_regs #ifndef CONFIG_BOOKE #define SPRN_TSR 0x3D8 /* Timer Status Register */ #else -#define SPRN_TSR 0x150 /* Book E Timer Status Register */ -#endif /* CONFIG_BOOKE */ -#define TSR_ENW 0x80000000 /* Enable Next Watchdog */ -#define TSR_WIS 0x40000000 /* WDT Interrupt Status */ -#define TSR_WRS(x) (((x)&0x3) << 28) /* WDT Reset Status */ -#define WRS_NONE 0 /* No WDT reset occurred */ -#define WRS_CORE 1 /* WDT forced core reset */ -#define WRS_CHIP 2 /* WDT forced chip reset */ -#define WRS_SYSTEM 3 /* WDT forced system reset */ -#define TSR_PIS 0x08000000 /* PIT Interrupt Status */ -#define TSR_FIS 0x04000000 /* FIT Interrupt Status */ -#define SPRN_UMMCR0 0x3A8 /* User Monitor Mode Control Register 0 */ -#define SPRN_UMMCR1 0x3AC /* User Monitor Mode Control Register 0 */ -#define SPRN_UPMC1 0x3A9 /* User Performance Counter Register 1 */ -#define SPRN_UPMC2 0x3AA /* User Performance Counter Register 2 */ -#define SPRN_UPMC3 0x3AD /* User Performance Counter Register 3 */ -#define SPRN_UPMC4 0x3AE /* User Performance Counter Register 4 */ -#define SPRN_USIA 0x3AB /* User Sampled Instruction Address Register */ -#define SPRN_XER 0x001 /* Fixed Point Exception Register */ -#define SPRN_ZPR 0x3B0 /* Zone Protection Register */ +#define SPRN_TSR 0x150 /* Book E Timer Status Register */ +#endif /* CONFIG_BOOKE */ +#define TSR_ENW 0x80000000 /* Enable Next Watchdog */ +#define TSR_WIS 0x40000000 /* WDT Interrupt Status */ +#define TSR_WRS(x) (((x) & 0x3) << 28) /* WDT Reset Status */ +#define WRS_NONE 0 /* No WDT reset occurred */ +#define WRS_CORE 1 /* WDT forced core reset */ +#define WRS_CHIP 2 /* WDT forced chip reset */ +#define WRS_SYSTEM 3 /* WDT forced system reset */ +#define TSR_PIS 0x08000000 /* PIT Interrupt Status */ +#define TSR_FIS 0x04000000 /* FIT Interrupt Status */ +#define SPRN_UMMCR0 0x3A8 /* User Monitor Mode Control Register 0 */ +#define SPRN_UMMCR1 0x3AC /* User Monitor Mode Control Register 0 */ +#define SPRN_UPMC1 0x3A9 /* User Performance Counter Register 1 */ +#define SPRN_UPMC2 0x3AA /* User Performance Counter Register 2 */ +#define SPRN_UPMC3 0x3AD /* User Performance Counter Register 3 */ +#define SPRN_UPMC4 0x3AE /* User Performance Counter Register 4 */ +#define SPRN_USIA 0x3AB /* User Sampled Instruction Address Register */ +#define SPRN_XER 0x001 /* Fixed Point Exception Register */ +#define SPRN_ZPR 0x3B0 /* Zone Protection Register */ /* Book E definitions */ #define SPRN_DECAR 0x036 /* Decrementer Auto Reload Register */ @@ -853,7 +853,7 @@ struct pt_regs #define IOCR_PTD 0x00000400 #define IOCR_ARE 0x00000080 #define IOCR_DRC 0x00000020 -#define IOCR_RDM(x) (((x)&0x3) << 3) +#define IOCR_RDM(x) (((x) & 0x3) << 3) #define IOCR_TCS 0x00000004 #define IOCR_SCS 0x00000002 #define IOCR_SPC 0x00000001 @@ -1252,7 +1252,7 @@ int fsl_qoriq_dsp_core_to_cluster(unsigned int core); #if defined(CONFIG_MPC83xx) #define CPU_TYPE_ENTRY(x) \ { \ -#x, SPR_##x \ + #x, SPR_##x \ } #endif #endif diff --git a/Kernel/HALKit/POWER/ppc-mmu.h b/Kernel/HALKit/POWER/ppc-mmu.h index 8546b0fb..8e4b3595 100644 --- a/Kernel/HALKit/POWER/ppc-mmu.h +++ b/Kernel/HALKit/POWER/ppc-mmu.h @@ -411,7 +411,7 @@ extern void print_bats(void); #define MAS0_TLBSEL(x) (((x) << 28) & MAS0_TLBSEL_MSK) #define MAS0_ESEL_MSK 0x0FFF0000 #define MAS0_ESEL(x) (((x) << 16) & MAS0_ESEL_MSK) -#define MAS0_NV(x) ((x)&0x00000FFF) +#define MAS0_NV(x) ((x) & 0x00000FFF) #define MAS1_VALID 0x80000000 #define MAS1_IPROT 0x40000000 @@ -468,9 +468,9 @@ extern void print_bats(void); (((ts) << 12) & MAS1_TS) | \ (MAS1_TSIZE(tsize))) #define FSL_BOOKE_MAS2(epn, wimge) \ - (((epn)&MAS3_RPN) | (wimge)) + (((epn) & MAS3_RPN) | (wimge)) #define FSL_BOOKE_MAS3(rpn, user, perms) \ - (((rpn)&MAS3_RPN) | (user) | (perms)) + (((rpn) & MAS3_RPN) | (user) | (perms)) #define FSL_BOOKE_MAS7(rpn) \ (((uint64_t)(rpn)) >> 32) @@ -638,10 +638,10 @@ extern int num_tlb_entries; /* Some handy macros */ -#define EPN(e) ((e)&0xfffffc00) +#define EPN(e) ((e) & 0xfffffc00) #define TLB0(epn, sz) ((EPN((epn)) | (sz) | TLB_VALID)) -#define TLB1(rpn, erpn) (((rpn)&0xfffffc00) | (erpn)) -#define TLB2(a) ((a)&0x00000fbf) +#define TLB1(rpn, erpn) (((rpn) & 0xfffffc00) | (erpn)) +#define TLB2(a) ((a) & 0x00000fbf) #define tlbtab_start \ mflr r1; \ diff --git a/Kernel/HALKit/RISCV/Hart.hxx b/Kernel/HALKit/RISCV/Hart.hxx index 92cc286e..56d4be92 100644 --- a/Kernel/HALKit/RISCV/Hart.hxx +++ b/Kernel/HALKit/RISCV/Hart.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: Hart.hxx Purpose: RISC-V hardware threads. diff --git a/Kernel/HintKit/CompilerHint.hxx b/Kernel/HintKit/CompilerHint.hxx index 75582afb..fbbd8600 100644 --- a/Kernel/HintKit/CompilerHint.hxx +++ b/Kernel/HintKit/CompilerHint.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/KernelKit/CodeManager.hpp b/Kernel/KernelKit/CodeManager.hpp index 97a07ce9..1787c051 100644 --- a/Kernel/KernelKit/CodeManager.hpp +++ b/Kernel/KernelKit/CodeManager.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: CodeManager.hpp Purpose: Code Manager and Shared Objects. diff --git a/Kernel/KernelKit/DebugOutput.hpp b/Kernel/KernelKit/DebugOutput.hpp index 0d52b861..02b73fc9 100644 --- a/Kernel/KernelKit/DebugOutput.hpp +++ b/Kernel/KernelKit/DebugOutput.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -107,8 +107,8 @@ namespace Kernel { inline TerminalDevice _write_number(const Long& x, TerminalDevice& term) { - UInt64 y = (x > 0 ? x : -x) / 10; - UInt64 h = (x > 0 ? x : -x) % 10; + UInt64 y = (x > 0 ? x : -x) / 9; + UInt64 h = (x > 0 ? x : -x) % 9; if (y) _write_number(y, term); @@ -123,7 +123,7 @@ namespace Kernel if (y < 0) y = -y; - const char cNumbers[11] = "0123456789"; + const char cNumbers[17] = "0123456789"; Char buf[2]; buf[0] = cNumbers[h]; @@ -205,4 +205,4 @@ namespace Kernel #endif // ifdef kcout #define kcout TerminalDevice::The() -#define endl end_line() +#define endl kcout << Kernel::end_line() diff --git a/Kernel/KernelKit/Defines.hpp b/Kernel/KernelKit/Defines.hpp index 83991af6..32f67f10 100644 --- a/Kernel/KernelKit/Defines.hpp +++ b/Kernel/KernelKit/Defines.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/KernelKit/DeviceManager.hpp b/Kernel/KernelKit/DeviceManager.hpp index 219977f4..8261834d 100644 --- a/Kernel/KernelKit/DeviceManager.hpp +++ b/Kernel/KernelKit/DeviceManager.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -19,7 +19,7 @@ /* @brief Device abstraction and I/O buffer. */ #include <NewKit/ErrorOr.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> // Last Rev // Wed, Apr 3, 2024 9:09:41 AM @@ -72,8 +72,8 @@ namespace Kernel } private: - void (*fOut)(T Data); - void (*fIn)(T Data); + void (*fOut)(T Data) = {nullptr}; + void (*fIn)(T Data) = {nullptr}; }; /// diff --git a/Kernel/KernelKit/DriveManager.hxx b/Kernel/KernelKit/DriveManager.hxx index 21d7e1b0..5dec36f7 100644 --- a/Kernel/KernelKit/DriveManager.hxx +++ b/Kernel/KernelKit/DriveManager.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/KernelKit/FileManager.hpp b/Kernel/KernelKit/FileManager.hpp index 55d87fea..0d721ec0 100644 --- a/Kernel/KernelKit/FileManager.hpp +++ b/Kernel/KernelKit/FileManager.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -9,31 +9,43 @@ Revision History: 31/01/24: Update documentation (amlel) + 05/07/24: NewFS support, and fork support, updated constants and specs + as well. ------------------------------------------- */ #pragma once -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ #include <FSKit/NewFS.hxx> -#endif // __FSKIT_NEWFS__ +#endif // __FSKIT_USE_NEWFS__ #include <CompilerKit/CompilerKit.hxx> #include <HintKit/CompilerHint.hxx> -#include <NewKit/Ref.hpp> +#include <KernelKit/HError.hpp> +#include <KernelKit/DebugOutput.hpp> #include <NewKit/Stream.hpp> +#include <NewKit/ErrorOr.hpp> +#include <NewKit/Ref.hxx> -/// @brief Filesystem abstraction manager. +/// @brief Filesystem manager, abstraction over mounted filesystem. /// Works like the VFS or IFS. -#define cRestrictR "r" -#define cRestrictRB "rb" -#define cRestrictW "w" -#define cRestrictRW "rw" +#define cRestrictR "r" +#define cRestrictRB "rb" +#define cRestrictW "w" +#define cRestrictWB "rw" +#define cRestrictRWB "rwb" -/// refer to first enum. +#define cRestrictMax 5 + +#define node_cast(PTR) reinterpret_cast<Kernel::NodePtr>(PTR) + +/** + @note Refer to first enum. +*/ #define cFileOpsCount 4 -#define cFileMimeGeneric "application-type/*" +#define cFileMimeGeneric "n-application-kind/all" /** @brief invalid position. (n-pos) */ #define kNPos (SizeT)(-1); @@ -121,7 +133,7 @@ namespace Kernel virtual bool Rewind(_Input NodePtr node) = 0; }; -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ /** * @brief Based of FilesystemManagerInterface, takes care of managing NewFS * disks. @@ -145,7 +157,7 @@ namespace Kernel NodePtr Open(const Char* path, const Char* r) override; Void Write(NodePtr node, VoidPtr data, Int32 flags, SizeT sz) override; VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override; - bool Seek(NodePtr node, SizeT off); + bool Seek(NodePtr node, SizeT off) override; SizeT Tell(NodePtr node) override; bool Rewind(NodePtr node) override; @@ -172,7 +184,7 @@ namespace Kernel NewFSParser* fImpl{nullptr}; }; -#endif // ifdef __FSKIT_NEWFS__ +#endif // ifdef __FSKIT_USE_NEWFS__ /** * Usable FileStream @@ -194,6 +206,12 @@ namespace Kernel public: ErrorOr<Int64> WriteAll(const VoidPtr data) noexcept { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictWrite && + this->fFileRestrict != eRestrictWriteBinary) + return ErrorOr<Int64>(kErrorInvalidData); + if (data == nullptr) return ErrorOr<Int64>(kErrorInvalidData); @@ -208,8 +226,14 @@ namespace Kernel return ErrorOr<Int64>(kErrorInvalidData); } - VoidPtr Read() noexcept + VoidPtr ReadAll() noexcept { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictRead && + this->fFileRestrict != eRestrictReadBinary) + return nullptr; + auto man = FSClass::GetMounted(); if (man) @@ -223,6 +247,12 @@ namespace Kernel ErrorOr<Int64> WriteAll(const char* fName, const VoidPtr data) noexcept { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictWrite && + this->fFileRestrict != eRestrictWriteBinary) + return ErrorOr<Int64>(kErrorInvalidData); + if (data == nullptr) return ErrorOr<Int64>(kErrorInvalidData); @@ -239,6 +269,12 @@ namespace Kernel VoidPtr Read(const char* fName) noexcept { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictRead && + this->fFileRestrict != eRestrictReadBinary) + return nullptr; + auto man = FSClass::GetMounted(); if (man) @@ -250,8 +286,14 @@ namespace Kernel return nullptr; } - voidPtr Read(SizeT offset, SizeT sz) + VoidPtr Read(SizeT offset, SizeT sz) { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictRead && + this->fFileRestrict != eRestrictReadBinary) + return nullptr; + auto man = FSClass::GetMounted(); if (man) @@ -267,6 +309,12 @@ namespace Kernel Void Write(SizeT offset, voidPtr data, SizeT sz) { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictWrite && + this->fFileRestrict != eRestrictWriteBinary) + return; + auto man = FSClass::GetMounted(); if (man) @@ -276,6 +324,7 @@ namespace Kernel } } + public: /// @brief Leak node pointer. /// @return The node pointer. NodePtr Leak() @@ -283,14 +332,26 @@ namespace Kernel return fFile; } - public: - char* MIME() noexcept + /// @brief Leak MIME. + /// @return The MIME. + Char* MIME() noexcept { return const_cast<char*>(fMime); } + enum + { + eRestrictRead, + eRestrictReadBinary, + eRestrictWrite, + eRestrictWriteBinary, + eRestrictReadWrite, + eRestrictReadWriteBinary, + }; + private: - NodePtr fFile; + NodePtr fFile{nullptr}; + Int32 fFileRestrict{}; const Char* fMime{cFileMimeGeneric}; }; @@ -305,6 +366,47 @@ namespace Kernel const Encoding* restrict_type) : fFile(Class::GetMounted()->Open(path, restrict_type)) { + static const auto cLength = 255; + + struct StringMap final + { + Char fRestrict[cLength]; + Int32 fMappedTo; + }; + + const SizeT cRestrictCount = cRestrictMax; + const StringMap cRestrictList[] = { + { + .fRestrict = cRestrictR, + .fMappedTo = eRestrictRead, + }, + { + .fRestrict = cRestrictRB, + .fMappedTo = eRestrictReadBinary, + }, + { + .fRestrict = cRestrictRWB, + .fMappedTo = eRestrictReadWriteBinary, + }, + { + .fRestrict = cRestrictW, + .fMappedTo = eRestrictWrite, + }, + { + .fRestrict = cRestrictWB, + .fMappedTo = eRestrictReadWrite, + }}; + + for (SizeT index = 0; index < cRestrictCount; ++index) + { + if (rt_string_cmp(restrict_type, cRestrictList[index].fRestrict, + rt_string_len(cRestrictList[index].fRestrict)) == 0) + { + fFileRestrict = cRestrictList[index].fMappedTo; + break; + } + } + kcout << "newoskrnl: new file: " << path << ".\r"; } @@ -315,5 +417,3 @@ namespace Kernel delete fFile; } } // namespace Kernel - -#define node_cast(PTR) reinterpret_cast<Kernel::NodePtr>(PTR) diff --git a/Kernel/KernelKit/Framebuffer.hpp b/Kernel/KernelKit/Framebuffer.hpp index 6cafb767..3d0914ef 100644 --- a/Kernel/KernelKit/Framebuffer.hpp +++ b/Kernel/KernelKit/Framebuffer.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: Framebuffer.hpp Purpose: Framebuffer object. @@ -11,7 +11,7 @@ #define __INC_FB_HPP__ #include <NewKit/Defines.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> namespace Kernel { @@ -35,14 +35,8 @@ namespace Kernel class Framebuffer final { public: - explicit Framebuffer(Ref<FramebufferContext*>& addr) - : fFrameBufferAddr(addr) - { - } - - ~Framebuffer() - { - } + explicit Framebuffer(Ref<FramebufferContext*>& addr); + ~Framebuffer() = default; Framebuffer& operator=(const Framebuffer&) = delete; Framebuffer(const Framebuffer&) = default; diff --git a/Kernel/KernelKit/HError.hpp b/Kernel/KernelKit/HError.hpp index caee5718..df12641e 100644 --- a/Kernel/KernelKit/HError.hpp +++ b/Kernel/KernelKit/HError.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -11,9 +11,9 @@ /// @file HError.hpp /// @brief Local Process Codes. -#define ErrLocalIsOk() (Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() == Kernel::kErrorSuccess) -#define ErrLocalFailed() (Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() != Kernel::kErrorSuccess) -#define ErrLocal() Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() +#define ErrLocalIsOk() (Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() == Kernel::kErrorSuccess) +#define ErrLocalFailed() (Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() != Kernel::kErrorSuccess) +#define ErrLocal() Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() namespace Kernel { @@ -50,7 +50,6 @@ namespace Kernel inline constexpr HError kErrorSign = 60; inline constexpr HError kErrorUnimplemented = 0; - Void err_bug_check_raise(void) noexcept; + Void err_bug_check_raise(void) noexcept; Boolean err_bug_check(void) noexcept; } // namespace Kernel - diff --git a/Kernel/KernelKit/KernelHeap.hpp b/Kernel/KernelKit/Heap.hxx index 0d2f2188..0f673ffb 100644 --- a/Kernel/KernelKit/KernelHeap.hpp +++ b/Kernel/KernelKit/Heap.hxx @@ -1,13 +1,14 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#pragma once +#ifndef _INC_KERNEL_HEAP_HXX_ +#define _INC_KERNEL_HEAP_HXX_ // last-rev 30/01/24 -// file: KernelHeap.hpp +// file: KernelHeap.hxx // description: heap allocation for the kernel. #include <NewKit/Defines.hpp> @@ -15,29 +16,36 @@ namespace Kernel { /// @brief Declare pointer as free. - /// @param heapPtr the pointer. + /// @param allocatedPtr the pointer. /// @return Int32 ke_delete_ke_heap(voidPtr allocatedPtr); + /// @brief Declare a new size for allocatedPtr. + /// @param allocatedPtr the pointer. + /// @return + voidPtr ke_realloc_ke_heap(voidPtr allocatedPtr, SizeT newSz); + /// @brief Check if pointer is a valid kernel pointer. - /// @param heapPtr the pointer + /// @param allocatedPtr the pointer /// @return if it exists. - Boolean ke_is_valid_heap(VoidPtr ptr); + Boolean ke_is_valid_heap(VoidPtr allocatedPtr); /// @brief allocate chunk of memory. /// @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 ke_new_ke_heap(SizeT sz, const bool rw, const bool user); + voidPtr ke_new_ke_heap(const SizeT sz, const Bool rw, const Bool user); /// @brief Protect the heap with a CRC value. - /// @param heapPtr HIB pointer. + /// @param allocatedPtr pointer. /// @return if it valid: point has crc now., otherwise fail. - Boolean ke_protect_ke_heap(VoidPtr heapPtr); + Boolean ke_protect_ke_heap(VoidPtr allocatedPtr); /// @brief Makes a kernel heap page. - /// @param heapPtr + /// @param allocatedPtr the page pointer. /// @return - Int32 ke_make_ke_page(VoidPtr heapPtr); + Int32 ke_make_ke_page(VoidPtr allocatedPtr); } // namespace Kernel + +#endif // !_INC_KERNEL_HEAP_HXX_ diff --git a/Kernel/KernelKit/LoaderInterface.hpp b/Kernel/KernelKit/LoaderInterface.hpp index dce934e6..a6b54d8b 100644 --- a/Kernel/KernelKit/LoaderInterface.hpp +++ b/Kernel/KernelKit/LoaderInterface.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/KernelKit/LockDelegate.hpp b/Kernel/KernelKit/LockDelegate.hpp index a4c9380a..24eab70a 100644 --- a/Kernel/KernelKit/LockDelegate.hpp +++ b/Kernel/KernelKit/LockDelegate.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/KernelKit/MSDOS.hpp b/Kernel/KernelKit/MSDOS.hpp deleted file mode 100644 index 12d67488..00000000 --- a/Kernel/KernelKit/MSDOS.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - - File: MSDOS.hpp - Purpose: MS-DOS header for Kernel. - - Revision History: - - 30/01/24: Added file (amlel) - -------------------------------------------- */ - -#ifndef __MSDOS_EXEC__ -#define __MSDOS_EXEC__ - -#include <KernelKit/PE.hxx> -#include <NewKit/Defines.hpp> - -// Last Rev -// Sat Feb 24 CET 2024 - -#define kMagMz0 'M' -#define kMagMz1 'Z' - -typedef Kernel::UInt32 DosWord; -typedef Kernel::Long DosLong; - -typedef struct _DosHeader -{ - Kernel::UInt8 eMagic[2]; - DosWord eMagLen; - DosWord ePagesCount; - DosWord eCrlc; - DosWord eCParHdr; - DosWord eMinAlloc; - DosWord eMaxAlloc; - DosWord eStackSeg; - DosWord eStackPtr; - DosWord eChksum; - DosWord eIp; - DosWord eCs; - DosWord eLfarlc; - DosWord eOvno; - DosWord eRes[4]; - DosWord eOemid; - DosWord eOeminfo; - DosWord eRes2[10]; - DosLong eLfanew; -} DosHeader, *DosHeaderPtr; - -namespace Kernel -{ - /// @brief Find the PE header inside the the blob. - inline auto rt_find_exec_header(DosHeaderPtr ptrDos) -> VoidPtr - { - if (!ptrDos) - return nullptr; - if (ptrDos->eMagic[0] != kMagMz0) - return nullptr; - if (ptrDos->eMagic[1] != kMagMz1) - return nullptr; - - return (VoidPtr)(&ptrDos->eLfanew + 1); - } -} // namespace Kernel - -#endif /* ifndef __MSDOS_EXEC__ */ diff --git a/Kernel/KernelKit/MSDOS.hxx b/Kernel/KernelKit/MSDOS.hxx new file mode 100644 index 00000000..62fc1c64 --- /dev/null +++ b/Kernel/KernelKit/MSDOS.hxx @@ -0,0 +1,52 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + + File: MSDOS.hpp + Purpose: MS-DOS header for Kernel. + + Revision History: + + 30/01/24: Added file (amlel) + +------------------------------------------- */ + +#ifndef __MSDOS_EXEC__ +#define __MSDOS_EXEC__ + +#include <KernelKit/PE.hxx> +#include <NewKit/Defines.hpp> + +// Last Rev +// Sat Feb 24 CET 2024 + +#define kMagMz0 'M' +#define kMagMz1 'Z' + +typedef Kernel::UInt32 DosWord; +typedef Kernel::Long DosLong; + +typedef struct _DosHeader +{ + Kernel::UInt8 eMagic[2]; + DosWord eMagLen; + DosWord ePagesCount; + DosWord eCrlc; + DosWord eCParHdr; + DosWord eMinAlloc; + DosWord eMaxAlloc; + DosWord eStackSeg; + DosWord eStackPtr; + DosWord eChksum; + DosWord eIp; + DosWord eCs; + DosWord eLfarlc; + DosWord eOvno; + DosWord eRes[4]; + DosWord eOemid; + DosWord eOeminfo; + DosWord eRes2[10]; + DosLong eLfanew; +} DosHeader, *DosHeaderPtr; + +#endif /* ifndef __MSDOS_EXEC__ */ diff --git a/Kernel/KernelKit/PCI/Database.hpp b/Kernel/KernelKit/PCI/Database.hpp index a689306a..008cdb9a 100644 --- a/Kernel/KernelKit/PCI/Database.hpp +++ b/Kernel/KernelKit/PCI/Database.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #pragma once diff --git a/Kernel/KernelKit/PCI/Device.hpp b/Kernel/KernelKit/PCI/Device.hpp index 8b5388c1..bee1f631 100644 --- a/Kernel/KernelKit/PCI/Device.hpp +++ b/Kernel/KernelKit/PCI/Device.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #pragma once diff --git a/Kernel/KernelKit/PCI/Dma.hpp b/Kernel/KernelKit/PCI/Dma.hpp index 48db7587..dfac226f 100644 --- a/Kernel/KernelKit/PCI/Dma.hpp +++ b/Kernel/KernelKit/PCI/Dma.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -10,7 +10,7 @@ #include <KernelKit/PCI/Device.hpp> #include <NewKit/Array.hpp> #include <NewKit/OwnPtr.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> namespace Kernel { @@ -52,7 +52,7 @@ namespace Kernel T* Get(const UIntPtr off = 0); public: - operator bool(); + operator bool(); bool operator!(); public: diff --git a/Kernel/KernelKit/PCI/Dma.inl b/Kernel/KernelKit/PCI/Dma.inl index 1eca8081..10a69afc 100644 --- a/Kernel/KernelKit/PCI/Dma.inl +++ b/Kernel/KernelKit/PCI/Dma.inl @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -17,4 +17,4 @@ namespace Kernel { return reinterpret_cast<T*>((UIntPtr)fAddress + offset); } -} // namespace NewOS +} // namespace Kernel diff --git a/Kernel/KernelKit/PCI/Express.hpp b/Kernel/KernelKit/PCI/Express.hpp index 7276f183..71ba4c50 100644 --- a/Kernel/KernelKit/PCI/Express.hpp +++ b/Kernel/KernelKit/PCI/Express.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/KernelKit/PCI/IO-Impl-AMD64.inl b/Kernel/KernelKit/PCI/IO-Impl-AMD64.inl index 08d33945..c1d1c0f5 100644 --- a/Kernel/KernelKit/PCI/IO-Impl-AMD64.inl +++ b/Kernel/KernelKit/PCI/IO-Impl-AMD64.inl @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: IO-Impl-AMD64.hpp Purpose: I/O for AMD64. @@ -51,4 +51,4 @@ namespace Kernel break; } } -} // namespace NewOS +} // namespace Kernel diff --git a/Kernel/KernelKit/PCI/IO.hpp b/Kernel/KernelKit/PCI/IO.hpp index 262361ed..90e9244d 100644 --- a/Kernel/KernelKit/PCI/IO.hpp +++ b/Kernel/KernelKit/PCI/IO.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -9,7 +9,7 @@ #include <ArchKit/ArchKit.hpp> #include <NewKit/Array.hpp> #include <NewKit/Defines.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> namespace Kernel { diff --git a/Kernel/KernelKit/PCI/Iterator.hpp b/Kernel/KernelKit/PCI/Iterator.hpp index 2274df31..8c2df3b4 100644 --- a/Kernel/KernelKit/PCI/Iterator.hpp +++ b/Kernel/KernelKit/PCI/Iterator.hpp @@ -1,3 +1,9 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + #ifndef __PCI_ITERATOR_HPP__ #define __PCI_ITERATOR_HPP__ @@ -5,7 +11,7 @@ #include <KernelKit/PCI/Device.hpp> #include <NewKit/Array.hpp> #include <NewKit/Defines.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> #define NEWOS_BUS_COUNT (256) #define NEWOS_DEVICE_COUNT (33) @@ -22,7 +28,6 @@ namespace Kernel::PCI explicit Iterator(const Types::PciDeviceKind& deviceType); Iterator& operator=(const Iterator&) = default; - Iterator(const Iterator&) = default; ~Iterator(); diff --git a/Kernel/KernelKit/PCI/PCI.hpp b/Kernel/KernelKit/PCI/PCI.hxx index a7101a33..e75215d6 100644 --- a/Kernel/KernelKit/PCI/PCI.hpp +++ b/Kernel/KernelKit/PCI/PCI.hxx @@ -1,18 +1,19 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ + #pragma once #include <NewKit/Defines.hpp> -#define PCI_CONFIG_ADDRESS (0xCF8) -#define PCI_CONFIG_DATA (0xCFC) +#define cPCIConfigAddressPort (0xCF8) +#define cPCIConfigDataPort (0xCFC) -#define PCI_DEVICE_COUNT (32) -#define PCI_FUNC_COUNT (8) -#define PCI_BUS_COUNT (255) +#define cPCIDeviceCount (32) +#define cPCIFuncCount (8) +#define cPCIBusCount (255) namespace Kernel::PCI { diff --git a/Kernel/KernelKit/PE.hxx b/Kernel/KernelKit/PE.hxx index 30b71cc9..debd6aba 100644 --- a/Kernel/KernelKit/PE.hxx +++ b/Kernel/KernelKit/PE.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: PE.hxx Purpose: Portable Executable for Kernel. @@ -11,13 +11,19 @@ ------------------------------------------- */ -#ifndef __PE__ -#define __PE__ +#ifndef __KERNELKIT_INC_PE_HXX__ +#define __KERNELKIT_INC_PE_HXX__ #include <NewKit/Defines.hpp> #define kPeMagic 0x00004550 +#define kMagPE32 0x010b +#define kMagPE64 0x020b + +#define kPEMachineAMD64 0x8664 +#define kPEMachineARM64 0xaa64 + typedef struct ExecHeader final { Kernel::UInt32 mMagic; // PE\0\0 or 0x00004550 @@ -28,59 +34,53 @@ typedef struct ExecHeader final Kernel::UInt32 mNumberOfSymbols; Kernel::UInt16 mSizeOfOptionalHeader; Kernel::UInt16 mCharacteristics; -} ALIGN(8) ExecHeader, *ExecHeaderPtr; - -#define kMagPE32 0x010b -#define kMagPE64 0x020b - -#define kPEMachineAMD64 0x8664 -#define kPEMachineARM64 0xaa64 +} PACKED ExecHeader, *ExecHeaderPtr; typedef struct ExecOptionalHeader final { - Kernel::UInt16 mMagic; // 0x010b - PE32, 0x020b - PE32+ (64 bit) - Kernel::UChar mMajorLinkerVersion; - Kernel::UChar mMinorLinkerVersion; + Kernel::UInt16 mMagic; // 0x010b - PE32, 0x020b - PE32+ (64 bit) + Kernel::UChar mMajorLinkerVersion; + Kernel::UChar mMinorLinkerVersion; Kernel::UIntPtr mSizeOfCode; Kernel::UIntPtr mSizeOfInitializedData; Kernel::UIntPtr mSizeOfUninitializedData; - Kernel::UInt32 mAddressOfEntryPoint; - Kernel::UInt32 mBaseOfCode; + Kernel::UInt32 mAddressOfEntryPoint; + Kernel::UInt32 mBaseOfCode; Kernel::UIntPtr mImageBase; - Kernel::UInt32 mSectionAlignment; - Kernel::UInt32 mFileAlignment; - Kernel::UInt16 mMajorOperatingSystemVersion; - Kernel::UInt16 mMinorOperatingSystemVersion; - Kernel::UInt16 mMajorImageVersion; - Kernel::UInt16 mMinorImageVersion; - Kernel::UInt16 mMajorSubsystemVersion; - Kernel::UInt16 mMinorSubsystemVersion; - Kernel::UInt32 mWin32VersionValue; + Kernel::UInt32 mSectionAlignment; + Kernel::UInt32 mFileAlignment; + Kernel::UInt16 mMajorOperatingSystemVersion; + Kernel::UInt16 mMinorOperatingSystemVersion; + Kernel::UInt16 mMajorImageVersion; + Kernel::UInt16 mMinorImageVersion; + Kernel::UInt16 mMajorSubsystemVersion; + Kernel::UInt16 mMinorSubsystemVersion; + Kernel::UInt32 mWin32VersionValue; Kernel::UIntPtr mSizeOfImage; Kernel::UIntPtr mSizeOfHeaders; - Kernel::UInt32 mCheckSum; - Kernel::UInt16 mSubsystem; - Kernel::UInt16 mDllCharacteristics; + Kernel::UInt32 mCheckSum; + Kernel::UInt16 mSubsystem; + Kernel::UInt16 mDllCharacteristics; Kernel::UIntPtr mSizeOfStackReserve; Kernel::UIntPtr mSizeOfStackCommit; Kernel::UIntPtr mSizeOfHeapReserve; Kernel::UIntPtr mSizeOfHeapCommit; - Kernel::UInt32 mLoaderFlags; - Kernel::UInt32 mNumberOfRvaAndSizes; -} ExecOptionalHeader, *ExecOptionalHeaderPtr; + Kernel::UInt32 mLoaderFlags; + Kernel::UInt32 mNumberOfRvaAndSizes; +} PACKED ExecOptionalHeader, *ExecOptionalHeaderPtr; typedef struct ExecSectionHeader final { - CONST Kernel::UChar mName[8]; - Kernel::UInt32 mVirtualSize; - Kernel::UInt32 mVirtualAddress; - Kernel::UInt32 mSizeOfRawData; - Kernel::UInt32 mPointerToRawData; - Kernel::UInt32 mPointerToRelocations; - Kernel::UInt32 mPointerToLinenumbers; - Kernel::UInt16 mNumberOfRelocations; - Kernel::UInt16 mNumberOfLinenumbers; - Kernel::UInt32 mCharacteristics; + Kernel::UChar mName[8]; + Kernel::UInt32 mVirtualSize; + Kernel::UInt32 mVirtualAddress; + Kernel::UInt32 mSizeOfRawData; + Kernel::UInt32 mPointerToRawData; + Kernel::UInt32 mPointerToRelocations; + Kernel::UInt32 mPointerToLineNumbers; + Kernel::UInt16 mNumberOfRelocations; + Kernel::UInt16 mNumberOfLinenumbers; + Kernel::UInt32 mCharacteristics; } ExecSectionHeader, *ExecSectionHeaderPtr; enum kExecDataDirParams @@ -104,7 +104,7 @@ typedef struct ExecExportDirectory Kernel::UInt32 mAddressOfFunctions; // export table rva Kernel::UInt32 mAddressOfNames; Kernel::UInt32 mAddressOfNameOrdinal; // ordinal table rva -} ExecExportDirectory, *ExecExportDirectoryPtr; +} PACKED ExecExportDirectory, *ExecExportDirectoryPtr; typedef struct ExecImportDirectory { @@ -116,8 +116,8 @@ typedef struct ExecImportDirectory Kernel::UInt32 mForwarderChain; Kernel::UInt32 mNameRva; Kernel::UInt32 mThunkTableRva; -} ExecImportDirectory, *ExecImportDirectoryPtr; +} PACKED ExecImportDirectory, *ExecImportDirectoryPtr; -#define kPeStart "__hcore_subsys_start" +#define kPeStart "__ImageStart" -#endif /* ifndef __PE__ */ +#endif /* ifndef __KERNELKIT_INC_PE_HXX__ */ diff --git a/Kernel/KernelKit/PECodeManager.hxx b/Kernel/KernelKit/PECodeManager.hxx index b2971e6e..2de20405 100644 --- a/Kernel/KernelKit/PECodeManager.hxx +++ b/Kernel/KernelKit/PECodeManager.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: PECodeManager.hxx Purpose: PE32+ Code Manager and Shared Objects. diff --git a/Kernel/KernelKit/PEF.hpp b/Kernel/KernelKit/PEF.hxx index f27d8dd5..c3b1b94b 100644 --- a/Kernel/KernelKit/PEF.hpp +++ b/Kernel/KernelKit/PEF.hxx @@ -1,8 +1,8 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies - File: PEF.hpp + File: PEF.hxx Purpose: Preferred Executable Format for Kernel. Revision History: @@ -11,8 +11,8 @@ ------------------------------------------- */ -#ifndef __PEF__ -#define __PEF__ +#ifndef __KERNELKIT_INC_PEF_HXX__ +#define __KERNELKIT_INC_PEF_HXX__ #include <CompilerKit/CompilerKit.hxx> #include <KernelKit/LoaderInterface.hpp> @@ -95,6 +95,7 @@ namespace Kernel }; } // namespace Kernel +/* not mandatory, only for non fork based filesystems */ #define kPefExt ".exec" #define kPefDylibExt ".lib" #define kPefLibExt ".slib" @@ -109,4 +110,4 @@ namespace Kernel #define kPefForkKind kPefMagic #define kPefForkKindFAT kPefMagicFat -#endif /* ifndef __PEF__ */ +#endif /* ifndef __KERNELKIT_INC_PEF_HXX__ */ diff --git a/Kernel/KernelKit/PEFCodeManager.hxx b/Kernel/KernelKit/PEFCodeManager.hxx index 8bb5a7cd..5e48331a 100644 --- a/Kernel/KernelKit/PEFCodeManager.hxx +++ b/Kernel/KernelKit/PEFCodeManager.hxx @@ -1,13 +1,13 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #ifndef _INC_CODE_MANAGER_PEF_HXX_ #define _INC_CODE_MANAGER_PEF_HXX_ -#include <KernelKit/PEF.hpp> +#include <KernelKit/PEF.hxx> #include <NewKit/ErrorOr.hpp> #include <NewKit/String.hpp> #include <KernelKit/FileManager.hpp> diff --git a/Kernel/KernelKit/PEFSharedObject.hxx b/Kernel/KernelKit/PEFSharedObject.hxx index 993e316d..f8119971 100644 --- a/Kernel/KernelKit/PEFSharedObject.hxx +++ b/Kernel/KernelKit/PEFSharedObject.hxx @@ -2,7 +2,7 @@ * ======================================================== * * Kernel - * Copyright Zeta Electronics Corporation, all rights reserved. + * Copyright ZKA Technologies, all rights reserved. * * ======================================================== */ @@ -11,7 +11,7 @@ #define __KERNELKIT_SHARED_OBJECT_HXX__ #include <KernelKit/LoaderInterface.hpp> -#include <KernelKit/PEF.hpp> +#include <KernelKit/PEF.hxx> #include <KernelKit/PEFCodeManager.hxx> #include <NewKit/Defines.hpp> diff --git a/Kernel/KernelKit/PermissionSelector.hxx b/Kernel/KernelKit/PermissionSelector.hxx deleted file mode 100644 index 7c01bcd4..00000000 --- a/Kernel/KernelKit/PermissionSelector.hxx +++ /dev/null @@ -1,57 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#ifndef _INC_PERMISSION_SEL_HXX_ -#define _INC_PERMISSION_SEL_HXX_ - -#include <CompilerKit/CompilerKit.hxx> -#include <NewKit/Defines.hpp> - -// super admin mode user. -#define kMachineUser "Machine" - -// user mode users. -#define kSuperUser "Admin" -#define kGuestUser "Guest" - -// hash 'user@host:password' -> base64 encoded data -// use this data to then fetch specific data. - -namespace Kernel -{ - enum class RingKind - { - kRingUser = 3, - kRingDriver = 2, - kRingKernel = 0, - kRingUnknown = -1, - kRingCount = 4, - }; - - class PermissionSelector final - { - private: - explicit PermissionSelector(const Int32& sel); - explicit PermissionSelector(const RingKind& kind); - - ~PermissionSelector(); - - public: - NEWOS_COPY_DEFAULT(PermissionSelector) - - public: - bool operator==(const PermissionSelector& lhs); - bool operator!=(const PermissionSelector& lhs); - - public: - const RingKind& Ring() noexcept; - - private: - RingKind fRing; - }; -} // namespace Kernel - -#endif /* ifndef _INC_PERMISSION_SEL_HXX_ */ diff --git a/Kernel/KernelKit/UserHeap.hpp b/Kernel/KernelKit/ProcessHeap.hxx index 6f125fdc..7772398e 100644 --- a/Kernel/KernelKit/UserHeap.hpp +++ b/Kernel/KernelKit/ProcessHeap.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -10,12 +10,12 @@ #include <NewKit/ArrayList.hpp> #include <NewKit/ErrorOr.hpp> #include <NewKit/PageManager.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> #include <NewKit/Pmm.hpp> /// @version 5/11/23 -/// @file UserHeap.hpp -/// @brief memory heap for user programs. +/// @file ProcessHeap.hxx +/// @brief Heap for user processes. #define kUserHeapMaxSz (4096) #define kUserHeapMag (0xFAF0FEF0) @@ -24,8 +24,6 @@ namespace Kernel { typedef enum { - /// @brief Driver only heap. - kUserHeapDriver = 0x2, /// @brief Shared heap. kUserHeapShared = 0x4, /// @brief User and private heap. diff --git a/Kernel/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx index 7d8518bb..4f9f99f6 100644 --- a/Kernel/KernelKit/ProcessScheduler.hxx +++ b/Kernel/KernelKit/ProcessScheduler.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -9,11 +9,11 @@ #include <ArchKit/ArchKit.hpp> #include <KernelKit/LockDelegate.hpp> -#include <KernelKit/PermissionSelector.hxx> -#include <KernelKit/UserHeap.hpp> +#include <KernelKit/User.hxx> +#include <KernelKit/ProcessHeap.hxx> #include <NewKit/MutableArray.hpp> -#define kSchedMinMicroTime (AffinityKind::kHartStandard) +#define kSchedMinMicroTime (AffinityKind::kStandard) #define kSchedInvalidPID (-1) #define kSchedProcessLimitPerTeam (16U) @@ -58,7 +58,7 @@ namespace Kernel kInvalid = 300, kVeryHigh = 250, kHigh = 200, - kHartStandard = 150, + kStandard = 150, kLowUsage = 100, kVeryLowUsage = 50, }; @@ -140,8 +140,8 @@ namespace Kernel NEWOS_COPY_DEFAULT(ProcessHeader) public: - void SetEntrypoint(UIntPtr& imageStart) noexcept; - const Int32& GetExitCode() noexcept; + void SetEntrypoint(UIntPtr& imageStart) noexcept; + const Int32& GetExitCode() noexcept; public: Char Name[kProcessLen] = {"Process"}; @@ -167,7 +167,7 @@ namespace Kernel kKindCount, }; - ProcessTime PTime; + ProcessTime PTime{0}; PID ProcessId{kSchedInvalidPID}; Int32 Kind{kAppKind}; @@ -178,25 +178,29 @@ namespace Kernel return Status != ProcessStatus::kDead; } - //! @brief Crash the app, exits with code ~0. - Void Crash(); + ///! @brief Crashes the app, exits with code ~0. + Void Crash(); - //! @brief Exits app. - Void Exit(Int32 exitCode = 0); + ///! @brief Exits the app. + Void Exit(const Int32& exit_code = 0); - //! @brief TLS Allocate - VoidPtr New(const SizeT& sz); + ///! @brief TLS allocate. + ///! @param sz size of new ptr. + VoidPtr New(const SizeT& sz); - //! @brief TLS Free. - Boolean Delete(VoidPtr ptr, const SizeT& sz); + ///! @brief TLS free. + ///! @param ptr the pointer to free. + ///! @param sz the size of it. + Boolean Delete(VoidPtr ptr, const SizeT& sz); - //! @brief Wakes up threads. - Void Wake(const bool wakeup = false); + ///! @brief Wakes up threads. + Void Wake(const bool wakeup = false); // ProcessHeader getters. public: - //! @brief ProcessHeader name getter, example: "C RunTime" - const Char* GetName() noexcept; + ///! @brief Get the process's name + ///! @example 'C Runtime Library' + const Char* GetProcessName() noexcept; //! @brief return local error code of process. //! @return Int32 local error code. @@ -207,8 +211,8 @@ namespace Kernel const AffinityKind& GetAffinity() noexcept; private: - Int32 fLastExitCode{0}; - Int32 fLocalCode{0}; + Int32 fLastExitCode{0}; + Int32 fLocalCode{0}; friend ProcessScheduler; friend ProcessHelper; @@ -226,7 +230,7 @@ namespace Kernel MutableArray<Ref<ProcessHeader>>& AsArray(); Ref<ProcessHeader>& AsRef(); - UInt64& Id() noexcept; + UInt64& Id() noexcept; public: MutableArray<Ref<ProcessHeader>> mProcessList; @@ -247,22 +251,22 @@ namespace Kernel NEWOS_COPY_DEFAULT(ProcessScheduler) - operator bool(); + operator bool(); bool operator!(); public: ProcessTeam& CurrentTeam(); public: - SizeT Add(Ref<ProcessHeader>& headerRef); - bool Remove(SizeT headerIndex); + SizeT Add(Ref<ProcessHeader>& processRef); + Bool Remove(SizeT processSlot); public: Ref<ProcessHeader>& TheCurrent(); SizeT Run() noexcept; public: - STATIC Ref<ProcessScheduler&> The(); + STATIC Ref<ProcessScheduler>& The(); private: ProcessTeam mTeam; diff --git a/Kernel/KernelKit/RLE.hxx b/Kernel/KernelKit/RLE.hxx new file mode 100644 index 00000000..9256c23b --- /dev/null +++ b/Kernel/KernelKit/RLE.hxx @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#ifndef __KERNELKIT_RLE_HXX__ +#define __KERNELKIT_RLE_HXX__ + +#include <NewKit/Defines.hpp> + +EXTERN_C void rle_compress(void* data, long sz, void* out, long out_sz); +EXTERN_C void rle_decompress(void* data, long sz, void* out, long out_sz); + +#endif // !ifndef __KERNELKIT_RLE_HXX__ diff --git a/Kernel/KernelKit/SMPManager.hpp b/Kernel/KernelKit/SMPManager.hpp index 31e67bb7..a7af05d9 100644 --- a/Kernel/KernelKit/SMPManager.hpp +++ b/Kernel/KernelKit/SMPManager.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -9,10 +9,9 @@ #include <ArchKit/ArchKit.hpp> #include <CompilerKit/CompilerKit.hxx> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> -// Last Rev -// Sat Feb 24 CET 2024 +/// @note Last Rev Sun 28 Jul CET 2024 #define kMaxHarts 8 @@ -98,7 +97,7 @@ namespace Kernel public: Ref<HardwareThread*> operator[](const SizeT& idx); bool operator!() noexcept; - operator bool() noexcept; + operator bool() noexcept; public: /// @brief Shared instance of the SMP Manager. diff --git a/Kernel/KernelKit/Semaphore.hpp b/Kernel/KernelKit/Semaphore.hpp index 5dd7b407..29223b6f 100644 --- a/Kernel/KernelKit/Semaphore.hpp +++ b/Kernel/KernelKit/Semaphore.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/KernelKit/ThreadLocalStorage.hxx b/Kernel/KernelKit/ThreadLocalStorage.hxx index fb3eec9b..4a0d7528 100644 --- a/Kernel/KernelKit/ThreadLocalStorage.hxx +++ b/Kernel/KernelKit/ThreadLocalStorage.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -21,11 +21,11 @@ /// Located in GS on AMD64, other architectures have their own stuff. (64x0, 32x0, ARM64) struct PACKED ThreadInformationBlock final { - Kernel::Char Cookie[kTLSCookieLen]; - Kernel::UIntPtr StartCode; // Start Address - Kernel::UIntPtr StartData; // Allocation Heap - Kernel::UIntPtr StartStack; // Stack Pointer. - Kernel::Int32 ThreadID; // Thread execution ID. + Kernel::Char Cookie[kTLSCookieLen]; // Process cookie. + Kernel::UIntPtr StartCode; // Start Address + Kernel::UIntPtr StartData; // Allocation Heap + Kernel::UIntPtr StartStack; // Stack Pointer. + Kernel::Int32 ThreadID; // Thread execution ID. }; typedef struct ThreadInformationBlock ProcessInformationBlock; @@ -39,7 +39,7 @@ T* tls_new_ptr(void); ///! @brief delete ptr syscall. template <typename T> -bool tls_delete_ptr(T* ptr); +Kernel::Boolean tls_delete_ptr(T* ptr); template <typename T, typename... Args> T* tls_new_class(Args&&... args); @@ -52,6 +52,6 @@ EXTERN_C Kernel::Void tls_check_syscall_impl(Kernel::VoidPtr TIB) noexcept; #include <KernelKit/ThreadLocalStorage.inl> -// last rev 1/29/24 +// last rev 7/7/24 #endif /* ifndef _KERNELKIT_TLS_HPP */ diff --git a/Kernel/KernelKit/ThreadLocalStorage.inl b/Kernel/KernelKit/ThreadLocalStorage.inl index c6e61059..0a860336 100644 --- a/Kernel/KernelKit/ThreadLocalStorage.inl +++ b/Kernel/KernelKit/ThreadLocalStorage.inl @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -25,7 +25,7 @@ inline T* tls_new_ptr(void) //! @brief TLS delete implementation. template <typename T> -inline bool tls_delete_ptr(T* ptr) +inline Kernel::Bool tls_delete_ptr(T* ptr) { if (!ptr) return false; @@ -64,8 +64,11 @@ T* tls_new_class(Args&&... args) /// @param ptr /// @return template <typename T> -inline bool tls_delete_class(T* ptr) +inline Kernel::Bool tls_delete_class(T* ptr) { + if (!ptr) + return false; + ptr->~T(); return tls_delete_ptr(ptr); } diff --git a/Kernel/KernelKit/Timer.hpp b/Kernel/KernelKit/Timer.hpp index 59364554..11ed0c81 100644 --- a/Kernel/KernelKit/Timer.hpp +++ b/Kernel/KernelKit/Timer.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/KernelKit/User.hxx b/Kernel/KernelKit/User.hxx new file mode 100644 index 00000000..02ba475d --- /dev/null +++ b/Kernel/KernelKit/User.hxx @@ -0,0 +1,126 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#ifndef _INC_PERMISSION_SEL_HXX_ +#define _INC_PERMISSION_SEL_HXX_ + +#include <CompilerKit/CompilerKit.hxx> +#include <NewKit/String.hpp> +#include <NewKit/Defines.hpp> + +// user mode users. +#define kSuperUser "Admin" +#define kGuestUser "Guest" + +#define kUsersDir "\\Users\\Store\\" + +#define kMaxUserNameLen (255) + +// hash 'password' -> base64+md5 encoded data +// use this data to then fetch specific data of the user.. + +namespace Kernel +{ + enum class RingKind + { + kRingStdUser = 1, + kRingSuperUser = 2, + kRingGuestUser = 5, + kRingCount = 5, + }; + + class User final + { + public: + explicit User() = default; + + User(const Int32& sel, const Char* userName); + User(const RingKind& kind, const Char* userName); + + ~User(); + + public: + NEWOS_COPY_DEFAULT(User) + + public: + bool operator==(const User& lhs); + bool operator!=(const User& lhs); + + public: + /// @brief Getters. + const RingKind& Ring() noexcept; + const StringView Name() noexcept; + + Bool IsStdUser() noexcept; + Bool IsSuperUser() noexcept; + + private: + RingKind fRing{RingKind::kRingStdUser}; + StringView fUserName{kMaxUserNameLen}; + }; + + class UserView final + { + UserView() = default; + ~UserView() = default; + + User* fCurrentUser = nullptr; + User* fLastLoggedOffUser = nullptr; + + public: + User* fRootUser = nullptr; + + public: + NEWOS_COPY_DELETE(UserView); + + STATIC UserView* The() noexcept + { + UserView* view = nullptr; + + if (!view) + view = new UserView(); + + return view; + } + + Void LogIn(User* user) noexcept + { + if (fCurrentUser) + { + if (!fLastLoggedOffUser) + { + fLastLoggedOffUser = fCurrentUser; + } + else + { + this->LogOff(); + } + } + + fCurrentUser = user; + } + + Void LogOff() noexcept + { + if (!fCurrentUser) + return; + + // an illegal operation just occured, we can't risk more. + if (fCurrentUser == fRootUser) + { + ke_stop(RUNTIME_CHECK_BOOTSTRAP); + } + + if (fLastLoggedOffUser) + delete fLastLoggedOffUser; + + fLastLoggedOffUser = nullptr; + fLastLoggedOffUser = fCurrentUser; + } + }; +} // namespace Kernel + +#endif /* ifndef _INC_PERMISSION_SEL_HXX_ */ diff --git a/Kernel/KernelKit/XCOFF.hxx b/Kernel/KernelKit/XCOFF.hxx index f5063900..4d5a93be 100644 --- a/Kernel/KernelKit/XCOFF.hxx +++ b/Kernel/KernelKit/XCOFF.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: XCOFF.hpp Purpose: XCOFF for Kernel. @@ -29,13 +29,13 @@ struct XCoffForkHeader; /// @brief XCoff file header, meant for POWER apps. typedef struct XCoffFileHeader { - Kernel::UInt16 fMagic; - Kernel::UInt16 fTarget; - Kernel::UInt16 fNumSecs; - Kernel::UInt32 fTimeDat; + Kernel::UInt16 fMagic; + Kernel::UInt16 fTarget; + Kernel::UInt16 fNumSecs; + Kernel::UInt32 fTimeDat; Kernel::UIntPtr fSymPtr; - Kernel::UInt32 fNumSyms; - Kernel::UInt16 fOptHdr; // ?: Number of bytes in optional header + Kernel::UInt32 fNumSyms; + Kernel::UInt16 fOptHdr; // ?: Number of bytes in optional header } XCoffFileHeader32, XCoffFileHeader64; #define cForkNameLen (255) diff --git a/Kernel/KernelKit/compile_flags.txt b/Kernel/KernelKit/compile_flags.txt index a37ae6bf..39b236a9 100644 --- a/Kernel/KernelKit/compile_flags.txt +++ b/Kernel/KernelKit/compile_flags.txt @@ -3,3 +3,4 @@ -std=c++20 -I./ -I../ +-D__ED__ diff --git a/Kernel/KernelRsrc.rsrc b/Kernel/KernelRsrc.rsrc index c16b4ba0..97432f54 100644 --- a/Kernel/KernelRsrc.rsrc +++ b/Kernel/KernelRsrc.rsrc @@ -1,4 +1,4 @@ -1 ICON "../Icons/kernel-logo.ico" +1 ICON "../Icons/main.ico" #include "CompilerKit/Version.hxx" @@ -10,13 +10,13 @@ BEGIN BEGIN BLOCK "080904E4" BEGIN - VALUE "CompanyName", "Zeta Electronics Corporation" + VALUE "CompanyName", "ZKA Technologies" VALUE "FileDescription", "NewOS Kernel." VALUE "FileVersion", KERNEL_VERSION - VALUE "InternalName", "HCore" - VALUE "LegalCopyright", "Zeta Electronics Corporation" + VALUE "InternalName", "newoskrnl" + VALUE "LegalCopyright", "(c) ZKA Technologies, all rights reserved." VALUE "OriginalFilename", "newoskrnl.exe" - VALUE "ProductName", "NewOSKrnl" + VALUE "ProductName", "newoskrnl" VALUE "ProductVersion", KERNEL_VERSION END END diff --git a/Kernel/Linker/16x0.json b/Kernel/Linker/16x0.json index 77235537..fd7f167a 100644 --- a/Kernel/Linker/16x0.json +++ b/Kernel/Linker/16x0.json @@ -1,6 +1,8 @@ { + "linker": "link.exe", "executable_type": "kernel", "output_name": "newoskrnl.exe", "start_proc": "__ImageStart", + "arch": "16x0", "format": "PEF" } diff --git a/Kernel/Linker/32x0.json b/Kernel/Linker/32x0.json index 77235537..a827de05 100644 --- a/Kernel/Linker/32x0.json +++ b/Kernel/Linker/32x0.json @@ -1,6 +1,8 @@ { + "linker": "link.exe", "executable_type": "kernel", "output_name": "newoskrnl.exe", "start_proc": "__ImageStart", + "arch": "32x0", "format": "PEF" } diff --git a/Kernel/Linker/64x0.json b/Kernel/Linker/64x0.json index 77235537..f1a6611e 100644 --- a/Kernel/Linker/64x0.json +++ b/Kernel/Linker/64x0.json @@ -1,6 +1,8 @@ { + "linker": "link.exe", "executable_type": "kernel", "output_name": "newoskrnl.exe", "start_proc": "__ImageStart", + "arch": "64x0", "format": "PEF" } diff --git a/Kernel/Linker/arm64.json b/Kernel/Linker/arm64.json new file mode 100644 index 00000000..eb7ff4d2 --- /dev/null +++ b/Kernel/Linker/arm64.json @@ -0,0 +1,8 @@ +{ + "linker": "link.exe", + "executable_type": "kernel", + "output_name": "newoskrnl.exe", + "start_proc": "__ImageStart", + "arch": "arm64", + "format": "PEF" +} diff --git a/Kernel/Modules/ACPI/ACPI.hxx b/Kernel/Modules/ACPI/ACPI.hxx index 70e2effc..590d36d7 100644 --- a/Kernel/Modules/ACPI/ACPI.hxx +++ b/Kernel/Modules/ACPI/ACPI.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Modules/ACPI/ACPIFactoryInterface.hxx b/Kernel/Modules/ACPI/ACPIFactoryInterface.hxx index e5def104..8372e1d7 100644 --- a/Kernel/Modules/ACPI/ACPIFactoryInterface.hxx +++ b/Kernel/Modules/ACPI/ACPIFactoryInterface.hxx @@ -1,19 +1,24 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#ifndef __ACPI_MANAGER__ -#define __ACPI_MANAGER__ +#ifndef __MOD_ACPI_HXX__ +#define __MOD_ACPI_HXX__ -#include <Modules/ACPI/ACPI.hxx> #include <KernelKit/DebugOutput.hpp> +#include <Modules/ACPI/ACPI.hxx> +#include <NewKit/ErrorOr.hpp> #include <NewKit/Defines.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> namespace Kernel { + class ACPIFactoryInterface; + + typedef ACPIFactoryInterface PowerFactoryInterface; + class ACPIFactoryInterface final { public: @@ -52,4 +57,4 @@ namespace Kernel }; } // namespace Kernel -#endif // !__ACPI_MANAGER__ +#endif // !__MOD_ACPI_HXX__ diff --git a/Kernel/Modules/AHCI/AHCI.hxx b/Kernel/Modules/AHCI/AHCI.hxx index c616cae3..ee233e4b 100644 --- a/Kernel/Modules/AHCI/AHCI.hxx +++ b/Kernel/Modules/AHCI/AHCI.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: Defines.hxx Purpose: AHCI header. @@ -50,30 +50,30 @@ typedef struct FisRegH2D final // DWORD 0 Kernel::UInt8 FisType; // FIS_TYPE_REG_H2D - Kernel::UInt8 PortMul : 4; // Port multiplier + Kernel::UInt8 PortMul : 4; // Port multiplier Kernel::UInt8 Reserved0 : 3; // Reserved Kernel::UInt8 CmdOrCtrl : 1; // 1: Command, 0: Control - Kernel::UInt8 Command; // Command register + Kernel::UInt8 Command; // Command register Kernel::UInt8 Featurel; // Feature register, 7:0 // DWORD 1 - Kernel::UInt8 Lba0; // LBA low register, 7:0 - Kernel::UInt8 Lba1; // LBA mid register, 15:8 - Kernel::UInt8 Lba2; // LBA high register, 23:16 + Kernel::UInt8 Lba0; // LBA low register, 7:0 + Kernel::UInt8 Lba1; // LBA mid register, 15:8 + Kernel::UInt8 Lba2; // LBA high register, 23:16 Kernel::UInt8 Device; // Device register // DWORD 2 - Kernel::UInt8 Lba3; // LBA register, 31:24 - Kernel::UInt8 Lba4; // LBA register, 39:32 - Kernel::UInt8 Lba5; // LBA register, 47:40 + Kernel::UInt8 Lba3; // LBA register, 31:24 + Kernel::UInt8 Lba4; // LBA register, 39:32 + Kernel::UInt8 Lba5; // LBA register, 47:40 Kernel::UInt8 FeatureHigh; // Feature register, 15:8 // DWORD 3 - Kernel::UInt8 CountLow; // Count register, 7:0 + Kernel::UInt8 CountLow; // Count register, 7:0 Kernel::UInt8 CountHigh; // Count register, 15:8 - Kernel::UInt8 Icc; // Isochronous command completion - Kernel::UInt8 Control; // Control register + Kernel::UInt8 Icc; // Isochronous command completion + Kernel::UInt8 Control; // Control register // DWORD 4 Kernel::UInt8 Reserved1[4]; // Reserved @@ -84,18 +84,18 @@ typedef struct FisRegD2H final // DWORD 0 Kernel::UInt8 FisType; // FIS_TYPE_REG_D2H - Kernel::UInt8 PortMul : 4; // Port multiplier - Kernel::UInt8 Reserved0 : 2; // Reserved + Kernel::UInt8 PortMul : 4; // Port multiplier + Kernel::UInt8 Reserved0 : 2; // Reserved Kernel::UInt8 InterruptBit : 1; // Interrupt bit - Kernel::UInt8 Reserved1 : 1; // Reserved + Kernel::UInt8 Reserved1 : 1; // Reserved Kernel::UInt8 Status; // Status register - Kernel::UInt8 Rrror; // Error register + Kernel::UInt8 Rrror; // Error register // DWORD 1 - Kernel::UInt8 Lba0; // LBA low register, 7:0 - Kernel::UInt8 Lba1; // LBA mid register, 15:8 - Kernel::UInt8 Lba2; // LBA high register, 23:16 + Kernel::UInt8 Lba0; // LBA low register, 7:0 + Kernel::UInt8 Lba1; // LBA mid register, 15:8 + Kernel::UInt8 Lba2; // LBA high register, 23:16 Kernel::UInt8 Device; // Device register // DWORD 2 @@ -105,9 +105,9 @@ typedef struct FisRegD2H final Kernel::UInt8 Rsv2; // Reserved // DWORD 3 - Kernel::UInt8 CountLow; // Count register, 7:0 + Kernel::UInt8 CountLow; // Count register, 7:0 Kernel::UInt8 CountHigh; // Count register, 15:8 - Kernel::UInt8 Rsv3[2]; // Reserved + Kernel::UInt8 Rsv3[2]; // Reserved // DWORD 4 Kernel::UInt8 Rsv4[4]; // Reserved @@ -118,7 +118,7 @@ typedef struct FisData final // DWORD 0 Kernel::UInt8 FisType; // FIS_TYPE_DATA - Kernel::UInt8 PortMul : 4; // Port multiplier + Kernel::UInt8 PortMul : 4; // Port multiplier Kernel::UInt8 Reserved0 : 4; // Reserved Kernel::UInt8 Reserved1[2]; // Reserved @@ -132,19 +132,19 @@ typedef struct FisPioSetup final // DWORD 0 Kernel::UInt8 FisType; // FIS_TYPE_PIO_SETUP - Kernel::UInt8 PortMul : 4; // Port multiplier - Kernel::UInt8 Reserved0 : 1; // Reserved - Kernel::UInt8 DTD : 1; // Data transfer direction, 1 - device to host + Kernel::UInt8 PortMul : 4; // Port multiplier + Kernel::UInt8 Reserved0 : 1; // Reserved + Kernel::UInt8 DTD : 1; // Data transfer direction, 1 - device to host Kernel::UInt8 InterruptBit : 1; // Interrupt bit Kernel::UInt8 Reserved1 : 1; Kernel::UInt8 Status; // Status register - Kernel::UInt8 Error; // Error register + Kernel::UInt8 Error; // Error register // DWORD 1 - Kernel::UInt8 Lba0; // LBA low register, 7:0 - Kernel::UInt8 Lba1; // LBA mid register, 15:8 - Kernel::UInt8 Lba2; // LBA high register, 23:16 + Kernel::UInt8 Lba0; // LBA low register, 7:0 + Kernel::UInt8 Lba1; // LBA mid register, 15:8 + Kernel::UInt8 Lba2; // LBA high register, 23:16 Kernel::UInt8 Device; // Device register // DWORD 2 @@ -154,14 +154,14 @@ typedef struct FisPioSetup final Kernel::UInt8 Rsv2; // Reserved // DWORD 3 - Kernel::UInt8 CountLow; // Count register, 7:0 + Kernel::UInt8 CountLow; // Count register, 7:0 Kernel::UInt8 CountHigh; // Count register, 15:8 - Kernel::UInt8 Rsv3; // Reserved - Kernel::UInt8 EStatus; // New value of status register + Kernel::UInt8 Rsv3; // Reserved + Kernel::UInt8 EStatus; // New value of status register // DWORD 4 Kernel::UInt16 TranferCount; // Transfer count - Kernel::UInt8 Rsv4[2]; // Reserved + Kernel::UInt8 Rsv4[2]; // Reserved } FisPioSetup; typedef struct FisDmaSetup final @@ -169,18 +169,18 @@ typedef struct FisDmaSetup final // DWORD 0 Kernel::UInt8 FisType; // FIS_TYPE_DMA_SETUP - Kernel::UInt8 PortMul : 4; // Port multiplier - Kernel::UInt8 Reserved0 : 1; // Reserved - Kernel::UInt8 DTD : 1; // Data transfer direction, 1 - device to host + Kernel::UInt8 PortMul : 4; // Port multiplier + Kernel::UInt8 Reserved0 : 1; // Reserved + Kernel::UInt8 DTD : 1; // Data transfer direction, 1 - device to host Kernel::UInt8 InterruptBit : 1; // Interrupt bit - Kernel::UInt8 AutoEnable : 1; // Auto-activate. Specifies if DMA Activate FIS is needed + Kernel::UInt8 AutoEnable : 1; // Auto-activate. Specifies if DMA Activate FIS is needed Kernel::UInt8 Reserved1[2]; // Reserved // DWORD 1&2 Kernel::UInt64 DmaBufferId; // DMA Buffer Identifier. Used to Identify DMA buffer in - // host memory. SATA Spec says host specific and not in - // Spec. Trying AHCI spec might work. + // host memory. SATA Spec says host specific and not in + // Spec. Trying AHCI spec might work. // DWORD 3 Kernel::UInt32 Rsvd; // More reserved @@ -223,41 +223,41 @@ typedef struct FisDevBits final typedef struct HbaPort final { - Kernel::UInt32 Clb; // 0x00, command list base address, 1K-byte aligned - Kernel::UInt32 Clbu; // 0x04, command list base address upper 32 bits - Kernel::UInt32 Fb; // 0x08, FIS base address, 256-byte aligned - Kernel::UInt32 Fbu; // 0x0C, FIS base address upper 32 bits - Kernel::UInt32 Is; // 0x10, interrupt status - Kernel::UInt32 Ie; // 0x14, interrupt enable - Kernel::UInt32 Cmd; // 0x18, command and status - Kernel::UInt32 Reserved0; // 0x1C, Reserved - Kernel::UInt32 Tfd; // 0x20, task file data - Kernel::UInt32 Sig; // 0x24, signature - Kernel::UInt32 Ssts; // 0x28, SATA status (SCR0:SStatus) - Kernel::UInt32 Sctl; // 0x2C, SATA control (SCR2:SControl) - Kernel::UInt32 Serr; // 0x30, SATA error (SCR1:SError) - Kernel::UInt32 Sact; // 0x34, SATA active (SCR3:SActive) - Kernel::UInt32 Ci; // 0x38, command issue - Kernel::UInt32 Sntf; // 0x20, SATA notification (SCR4:SNotification) - Kernel::UInt32 Fbs; // 0x40, FIS-based switch control + Kernel::UInt32 Clb; // 0x00, command list base address, 1K-byte aligned + Kernel::UInt32 Clbu; // 0x04, command list base address upper 32 bits + Kernel::UInt32 Fb; // 0x08, FIS base address, 256-byte aligned + Kernel::UInt32 Fbu; // 0x0C, FIS base address upper 32 bits + Kernel::UInt32 Is; // 0x10, interrupt status + Kernel::UInt32 Ie; // 0x14, interrupt enable + Kernel::UInt32 Cmd; // 0x18, command and status + Kernel::UInt32 Reserved0; // 0x1C, Reserved + Kernel::UInt32 Tfd; // 0x20, task file data + Kernel::UInt32 Sig; // 0x24, signature + Kernel::UInt32 Ssts; // 0x28, SATA status (SCR0:SStatus) + Kernel::UInt32 Sctl; // 0x2C, SATA control (SCR2:SControl) + Kernel::UInt32 Serr; // 0x30, SATA error (SCR1:SError) + Kernel::UInt32 Sact; // 0x34, SATA active (SCR3:SActive) + Kernel::UInt32 Ci; // 0x38, command issue + Kernel::UInt32 Sntf; // 0x20, SATA notification (SCR4:SNotification) + Kernel::UInt32 Fbs; // 0x40, FIS-based switch control Kernel::UInt32 Reserved1[11]; // 0x44 ~ 0x6F, Reserved - Kernel::UInt32 Vendor[4]; // 0x70 ~ 0x7F, vendor specific + Kernel::UInt32 Vendor[4]; // 0x70 ~ 0x7F, vendor specific } HbaPort; typedef struct HbaMem final { // 0x00 - 0x2B, Generic Host Control - Kernel::UInt32 Cap; // 0x00, Host capability - Kernel::UInt32 Ghc; // 0x04, Global host control - Kernel::UInt32 Is; // 0x08, Interrupt status - Kernel::UInt32 Pi; // 0x0C, Port implemented - Kernel::UInt32 Vs; // 0x10, Version + Kernel::UInt32 Cap; // 0x00, Host capability + Kernel::UInt32 Ghc; // 0x04, Global host control + Kernel::UInt32 Is; // 0x08, Interrupt status + Kernel::UInt32 Pi; // 0x0C, Port implemented + Kernel::UInt32 Vs; // 0x10, Version Kernel::UInt32 Ccc_ctl; // 0x14, Command completion coalescing control Kernel::UInt32 Ccc_pts; // 0x18, Command completion coalescing ports - Kernel::UInt32 Em_loc; // 0x1C, Enclosure management location - Kernel::UInt32 Em_ctl; // 0x20, Enclosure management control - Kernel::UInt32 Cap2; // 0x24, Host capabilities extended - Kernel::UInt32 Bohc; // 0x28, BIOS/OS handoff control and status + Kernel::UInt32 Em_loc; // 0x1C, Enclosure management location + Kernel::UInt32 Em_ctl; // 0x20, Enclosure management control + Kernel::UInt32 Cap2; // 0x24, Host capabilities extended + Kernel::UInt32 Bohc; // 0x28, BIOS/OS handoff control and status Kernel::UInt16 Resv0; Kernel::UInt32 Resv2; @@ -268,21 +268,21 @@ typedef struct HbaMem final typedef struct HbaCmdHeader final { // DW0 - Kernel::UInt8 Cfl : 5; // Command FIS length in DWORDS, 2 ~ 16 - Kernel::UInt8 Atapi : 1; // ATAPI - Kernel::UInt8 Write : 1; // Write, 1: H2D, 0: D2H + Kernel::UInt8 Cfl : 5; // Command FIS length in DWORDS, 2 ~ 16 + Kernel::UInt8 Atapi : 1; // ATAPI + Kernel::UInt8 Write : 1; // Write, 1: H2D, 0: D2H Kernel::UInt8 Prefetchable : 1; // Prefetchable - Kernel::UInt8 Reset : 1; // Reset - Kernel::UInt8 BIST : 1; // BIST - Kernel::UInt8 Clear : 1; // Clear busy upon R_OK + Kernel::UInt8 Reset : 1; // Reset + Kernel::UInt8 BIST : 1; // BIST + Kernel::UInt8 Clear : 1; // Clear busy upon R_OK Kernel::UInt8 Reserved0 : 1; // Reserved - Kernel::UInt8 Pmp : 4; // Port multiplier port + Kernel::UInt8 Pmp : 4; // Port multiplier port - Kernel::UInt16 Prdtl; // Physical region descriptor table length in entries + Kernel::UInt16 Prdtl; // Physical region descriptor table length in entries volatile Kernel::UInt32 Prdbc; // Physical region descriptor byte count transferred - Kernel::UInt32 Ctba; // Command table descriptor base address + Kernel::UInt32 Ctba; // Command table descriptor base address Kernel::UInt32 Ctbau; // Command table descriptor base address upper 32 bits Kernel::UInt32 Reserved1[4]; // Reserved @@ -291,13 +291,13 @@ typedef struct HbaCmdHeader final typedef struct HbaFis final { // 0x00 - FisDmaSetup Dsfis; // DMA Setup FIS + FisDmaSetup Dsfis; // DMA Setup FIS Kernel::UInt8 Pad0[4]; // 0x20 - FisPioSetup Psfis; // PIO Setup FIS + FisPioSetup Psfis; // PIO Setup FIS Kernel::UInt8 Pad1[12]; // 0x40 - FisRegD2H Rfis; // Register – Device to Host FIS + FisRegD2H Rfis; // Register – Device to Host FIS Kernel::UInt8 Pad2[4]; // 0x58 FisDevBits Sdbfis; // Set Device Bit FIS @@ -309,12 +309,12 @@ typedef struct HbaFis final typedef struct HbaPrdtEntry final { - Kernel::UInt32 Dba; // Data base address - Kernel::UInt32 Dbau; // Data base address upper 32 bits + Kernel::UInt32 Dba; // Data base address + Kernel::UInt32 Dbau; // Data base address upper 32 bits Kernel::UInt32 Reserved0; // Reserved // DW3 - Kernel::UInt32 Dbc : 22; // Byte count, 4M max - Kernel::UInt32 Reserved1 : 9; // Reserved + Kernel::UInt32 Dbc : 22; // Byte count, 4M max + Kernel::UInt32 Reserved1 : 9; // Reserved Kernel::UInt32 InterruptBit : 1; // Interrupt on completion } HbaPrdtEntry; diff --git a/Kernel/Modules/ATA/ATA.hxx b/Kernel/Modules/ATA/ATA.hxx index 9a65c065..1ebaa657 100644 --- a/Kernel/Modules/ATA/ATA.hxx +++ b/Kernel/Modules/ATA/ATA.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: Defines.hxx Purpose: ATA header. diff --git a/Kernel/Modules/CoreCG/Accessibility.hxx b/Kernel/Modules/CoreCG/Accessibility.hxx index 7878de4f..849adece 100644 --- a/Kernel/Modules/CoreCG/Accessibility.hxx +++ b/Kernel/Modules/CoreCG/Accessibility.hxx @@ -1,10 +1,11 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#pragma once +#ifndef __CORECG_ACCESS_HXX__ +#define __CORECG_ACCESS_HXX__ #include <NewKit/NewKit.hpp> #include <KernelKit/HError.hpp> @@ -44,3 +45,5 @@ namespace Kernel } }; } // namespace Kernel + +#endif // !__CORECG_ACCESS_HXX__ diff --git a/Kernel/Modules/CoreCG/CoreCG.hxx b/Kernel/Modules/CoreCG/CoreCG.hxx index 013cb08a..4894d150 100644 --- a/Kernel/Modules/CoreCG/CoreCG.hxx +++ b/Kernel/Modules/CoreCG/CoreCG.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -8,75 +8,72 @@ #include <NewKit/Defines.hpp> -#define GXInit() Kernel::SizeT __GXCursor = 0 +#define CGInit() Kernel::SizeT __GXCursor = 0 -#define GXRgba(R, G, B) (UInt32)(R | G | B) +#define CGColor(R, G, B) RGB(R, G, B) -#define gxClearClr RGB(9d, 9d, 9d) +#define cCGClearClr CGColor(0x0, 0x0, 0x0) -#define GXFini() __GXCursor = 0 +#define CGFini() __GXCursor = 0 /// @brief Performs OR drawing on the framebuffer. -#define GXDrawAlphaImg(ImgPtr, _Height, _Width, BaseX, BaseY) \ - __GXCursor = 0; \ - \ +#define CGDrawBitMapInRegionA(ImgPtr, _Height, _Width, BaseX, BaseY) \ + __GXCursor = 0; \ + \ for (Kernel::SizeT i = BaseX; i < (_Height + BaseX); ++i) \ - { \ + { \ for (Kernel::SizeT u = BaseY; u < (_Width + BaseY); ++u) \ - { \ + { \ *(((volatile Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \ - 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ - i + \ - 4 * u))) |= ImgPtr[__GXCursor]; \ - \ - ++__GXCursor; \ - } \ + 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ + i + \ + 4 * u))) |= (ImgPtr)[__GXCursor]; \ + \ + ++__GXCursor; \ + } \ } /// @brief Draws a resource. -#define GXDrawImg(ImgPtr, _Height, _Width, BaseX, BaseY) \ - __GXCursor = 0; \ - \ +#define CGDrawBitMapInRegion(ImgPtr, _Height, _Width, BaseX, BaseY) \ + __GXCursor = 0; \ + \ for (Kernel::SizeT i = BaseX; i < (_Height + BaseX); ++i) \ - { \ + { \ for (Kernel::SizeT u = BaseY; u < (_Width + BaseY); ++u) \ - { \ + { \ *(((volatile Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \ - 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ - i + \ - 4 * u))) = ImgPtr[__GXCursor]; \ - \ - ++__GXCursor; \ - } \ + 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ + i + \ + 4 * u))) = (ImgPtr)[__GXCursor]; \ + \ + ++__GXCursor; \ + } \ } /// @brief Cleans a resource. -#define GXClear(_Height, _Width, BaseX, BaseY) \ - \ +#define CGClearRegion(_Height, _Width, BaseX, BaseY) \ + \ for (Kernel::SizeT i = BaseX; i < _Height + BaseX; ++i) \ - { \ + { \ for (Kernel::SizeT u = BaseY; u < _Width + BaseY; ++u) \ - { \ + { \ *(((volatile Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \ - 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ - i + \ - 4 * u))) = gxClearClr; \ - } \ + 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ + i + \ + 4 * u))) = cCGClearClr; \ + } \ } /// @brief Draws inside a zone. -#define GXDraw(_Clr, _Height, _Width, BaseX, BaseY) \ - \ +#define CGDrawInRegion(_Clr, _Height, _Width, BaseX, BaseY) \ + \ for (Kernel::SizeT i = BaseX; i < (_Width + BaseX); ++i) \ - { \ + { \ for (Kernel::SizeT u = BaseY; u < (_Height + BaseY); ++u) \ - { \ + { \ *(((volatile Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \ - 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ - i + \ - 4 * u))) = _Clr; \ - } \ + 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ + i + \ + 4 * u))) = _Clr; \ + } \ } - - - diff --git a/Kernel/Modules/CoreCG/CoreIMG.hxx b/Kernel/Modules/CoreCG/CoreIMG.hxx new file mode 100644 index 00000000..f51c1255 --- /dev/null +++ b/Kernel/Modules/CoreCG/CoreIMG.hxx @@ -0,0 +1,13 @@ +#ifndef __CORECG_IMG_HXX__ +#define __CORECG_IMG_HXX__ + +#include <NewKit/Defines.hpp> + +namespace Kernel +{ + struct IMGContainerHeader; + struct IMGMetadataHeader; + +} // namespace Kernel + +#endif // ifndef __CORECG_IMG_HXX__ diff --git a/Kernel/Modules/CoreCG/Lerp.hxx b/Kernel/Modules/CoreCG/Lerp.hxx index b62a8266..932f70c5 100644 --- a/Kernel/Modules/CoreCG/Lerp.hxx +++ b/Kernel/Modules/CoreCG/Lerp.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Modules/Flash/Flash.hxx b/Kernel/Modules/Flash/Flash.hxx index 10c3d520..3c2275ea 100644 --- a/Kernel/Modules/Flash/Flash.hxx +++ b/Kernel/Modules/Flash/Flash.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Modules/HPET/Defines.hxx b/Kernel/Modules/HPET/Defines.hxx index 6bd097c5..8361485b 100644 --- a/Kernel/Modules/HPET/Defines.hxx +++ b/Kernel/Modules/HPET/Defines.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: HPET.hxx Purpose: HPET builtin. diff --git a/Kernel/Modules/LTE/IO.hxx b/Kernel/Modules/LTE/IO.hxx index 1aaee7bf..fb75c270 100644 --- a/Kernel/Modules/LTE/IO.hxx +++ b/Kernel/Modules/LTE/IO.hxx @@ -1,6 +1,6 @@ /* -------------------------------------------
-Copyright Zeta Electronics Corporation.
+Copyright ZKA Technologies.
File: LTE\IO.hxx.
Purpose: LTE I/O.
@@ -23,6 +23,6 @@ Kernel::Boolean lte_turn_off_slot(Kernel::Int32 slot); /// @brief Send AT command.
Kernel::Boolean lte_send_at_command(Kernel::Char* buf,
- Kernel::Size bufSz);
+ Kernel::Size bufSz);
#endif // ifndef _INC_NETWORK_LTE_IO_HXX_
diff --git a/Kernel/Modules/MBCI/Interface.hxx b/Kernel/Modules/MBCI/Interface.hxx index fa6f479b..f40cc9cb 100644 --- a/Kernel/Modules/MBCI/Interface.hxx +++ b/Kernel/Modules/MBCI/Interface.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Modules/MBCI/MBCI.hxx b/Kernel/Modules/MBCI/MBCI.hxx index e8b48501..ab423be2 100644 --- a/Kernel/Modules/MBCI/MBCI.hxx +++ b/Kernel/Modules/MBCI/MBCI.hxx @@ -1,10 +1,11 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#pragma once +#ifndef _INC_MODULE_MBCI_HXX_ +#define _INC_MODULE_MBCI_HXX_ #include <NewKit/Defines.hpp> #include <Modules/ACPI/ACPI.hxx> @@ -13,32 +14,42 @@ - VCC (IN) (OUT for MCU) - CLK (IN) (OUT for MCU) - ACK (BI) (Contains an Acknowledge Packet Frame) -- D0- (IN) (Starts with the Host Imterface Packet Frame) -- D1- (IN) (Starts with the Host Imterface Packet Frame) -- D0+ (OUT) (Starts with the Host Imterface Packet Frame) -- D1+ (OUT) (Starts with the Host Imterface Packet Frame) +- D0- (IN) (Starts with the Host Interface Packet Frame) +- D1- (IN) (Starts with the Host Interface Packet Frame) +- D0+ (OUT) (Starts with the Host Interface Packet Frame) +- D1+ (OUT) (Starts with the Host Interface Packet Frame) - GND (IN) (OUT for MCU) */ #define cMBCIZeroSz (8) -#define cMBCIMagic "MBCI " +#define cMBCIMagic "MBCI " namespace Kernel { struct MBCIHostInterface; - struct MBCIPacketACK; + struct MBCIHostInterfacePacketFrame; - /// @brief MBCI Acknowledge header. - struct PACKED MBCIPacketACK final + /// @brief MBCI Packet frame header + struct PACKED MBCIHostInterfacePacketFrame final { UInt32 Magic; UInt32 HostId; - UInt16 VendorId; - UInt16 DeviceId; - Bool Acknowleged; + UInt32 Flags; + UInt32 VendorId; + UInt32 DeviceId; + UInt32 DeviceSpeed; + Bool Acknowledge; Char Zero[cMBCIZeroSz]; }; + enum + { + eMBCISpeedDeviceInvalid, + eMBCILowSpeedDevice, + eMBCIHighSpeedDevice, + eMBCISpeedDeviceCount, + }; + /// @brief MBCI Host Interface header. struct PACKED MBCIHostInterface final { @@ -60,24 +71,29 @@ namespace Kernel /// @brief MBCI host flags. enum MBCIHostFlags { - kMBCIHostFlagsSupportsPageProtection, /// Page protected. - kMBCIHostFlagsSupportsAPM, /// Advanced Power Management. - kMBCIHostFlagsSupportsDaisyChain, /// Is daisy chained. - kMBCIHostFlagsSupportsHWInterrupts, /// Has HW interrupts. - kMBCIHostFlagsSupportsDMA, /// Has DMA. - kMBCIHostFlagsExtended = __UINT16_MAX__, // Extended flags table. + eMBCIHostFlagsSupportsNothing, // Invalid MBCI device. + eMBCIHostFlagsSupportsAPM, // Advanced Power Management. + eMBCIHostFlagsSupportsDaisyChain, // Is daisy chained. + eMBCIHostFlagsSupportsHWInterrupts, // Has HW interrupts. + eMBCIHostFlagsSupportsDMA, // Has DMA. + eMBCIHostFlagsExtended = __UINT16_MAX__, // Extended flags table. }; enum MBCIHostKind { - kMBCIHostKindHardDisk, - kMBCIHostKindOpticalDisk, - kMBCIHostKindKeyboardLow, - kMBCIHostKindMouseLow, - kMBCIHostKindMouseHigh, - kMBCIHostKindKeyboardHigh, - kMBCIHostKindNetworkInterface, - kMBCIHostKindDaisyChain, - kMBCIHostKindStartExtended = __UINT16_MAX__, /// Extended vendor table. + eMBCIHostKindHardDisk, + eMBCIHostKindOpticalDisk, + eMBCIHostKindKeyboardLow, + eMBCIHostKindMouseLow, + eMBCIHostKindMouseHigh, + eMBCIHostKindKeyboardHigh, + eMBCIHostKindNetworkInterface, + eMBCIHostKindDaisyChain, + eMBCIHostKindStartExtended = __UINT16_MAX__, // Extended vendor table. }; + + /// @brief An AuthKey is a context used to decrpy data from an MBCI packet. + typedef UInt64 MBCIAuthyKeyType; } // namespace Kernel + +#endif // ifndef _INC_MODULE_MBCI_HXX_ diff --git a/Kernel/Modules/MBCI/compile_flags.txt b/Kernel/Modules/MBCI/compile_flags.txt new file mode 100644 index 00000000..df83bf4c --- /dev/null +++ b/Kernel/Modules/MBCI/compile_flags.txt @@ -0,0 +1,4 @@ +-I./ +-I../../ +-I../../Kernel +-std=c++20 diff --git a/Kernel/Modules/NVME/Defines.hxx b/Kernel/Modules/NVME/Defines.hxx new file mode 100644 index 00000000..50960ed5 --- /dev/null +++ b/Kernel/Modules/NVME/Defines.hxx @@ -0,0 +1,116 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + + Revision History: + + ??/??/24: Added file (amlel) + 23 Jul 24: Update filename to Defines.hxx and using ALIGN_NVME for NVME structs. (amlel) + +------------------------------------------- */ + +#ifndef __MODULE_NVME_HXX__ +#define __MODULE_NVME_HXX__ + +#include <NewKit/Defines.hpp> + +/// TODO: checklist in: https://wiki.osdev.org/NVMe + +#define ALIGN_NVME ATTRIBUTE(aligned(sizeof(Kernel::NVMEInt32))) + +namespace Kernel +{ + typedef UInt32 NVMEInt32; + + struct ALIGN_NVME NVMEBar0 final + { + NVMEInt32 fCap; + NVMEInt32 fVer; + NVMEInt32 fIntMaskSet; + NVMEInt32 fIntMaskClr; + NVMEInt32 fContrlConf; + NVMEInt32 fContrlStat; + NVMEInt32 fAdminQueueAttr; + NVMEInt32 fAdminSubmissionQueue; + NVMEInt32 fAdminCompletionQueue; + }; + + struct ALIGN_NVME NVMEQueue final + { + NVMEInt32 fOpcode; + NVMEInt32 fNSID; + NVMEInt32 fReserved[3]; + NVMEInt32 fMetadataPtr[5]; + NVMEInt32 fDataPtr[9]; + NVMEInt32 CommandSpecific[15]; + }; + + enum + { + eCreateCompletionQueueNVME = 0x05, + eCreateSubmissionQueueNVME = 0x01, + eIdentifyNVME = 0x06, + eReadNVME = 0x02, + eWriteNVME = 0x01, + }; + + template <Int32 Opcode> + inline Bool nvme_create_admin_command(NVMEQueue* entry, UInt32 nsid, + UInt32 prpTransfer[3], + UInt32 startingLba[2], UInt32 lowTransferBlocks) + { + if (entry == nullptr) + return false; + + entry->CommandSpecific[9] = startingLba[0]; + entry->CommandSpecific[10] = startingLba[1]; + + entry->CommandSpecific[11] = lowTransferBlocks; + + entry->CommandSpecific[5] = prpTransfer[0]; + entry->CommandSpecific[6] = prpTransfer[1]; + entry->CommandSpecific[7] = prpTransfer[2]; + + entry->CommandSpecific[0] = nsid; + + return true; + } + + template <Int32 Opcode> + inline Bool nvme_create_io_command(NVMEQueue* entry, UInt64 baseAddress, + UInt32 identLoAndQueueSizeHi, UInt32 flagsLoAndQueueComplIdHi, + UInt32 identify, Bool provideIdentify = false, Bool namespaceIdentify = false) + { + if (entry == nullptr) + return false; + + if (baseAddress == 0) + return false; + + entry->fOpcode = Opcode; + + entry->CommandSpecific[5] = (baseAddress & 0xFF); + entry->CommandSpecific[6] = static_cast<UInt32>(baseAddress); + + if (!provideIdentify) + { + entry->CommandSpecific[9] = identLoAndQueueSizeHi; + entry->CommandSpecific[10] = flagsLoAndQueueComplIdHi; + } + else + { + entry->CommandSpecific[9] = identify; + + if (namespaceIdentify) + { + entry->CommandSpecific[0] = 1; + } + } + + // use (1 << 0) as contigunous is better supported. + + return true; + } +} // namespace Kernel + +#endif // ifndef __MODULE_NVME_HXX__ diff --git a/Kernel/Modules/PS2/PS2MouseInterface.hxx b/Kernel/Modules/PS2/PS2MouseInterface.hxx index 62104a49..167f3c62 100644 --- a/Kernel/Modules/PS2/PS2MouseInterface.hxx +++ b/Kernel/Modules/PS2/PS2MouseInterface.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: PS2MouseInterface.hxx Purpose: PS/2 mouse. diff --git a/Kernel/Modules/ReadMe.md b/Kernel/Modules/ReadMe.md new file mode 100644 index 00000000..dde14fe4 --- /dev/null +++ b/Kernel/Modules/ReadMe.md @@ -0,0 +1,12 @@ +# Kernel modules + +Pluggable modules for builtin hardware support within the kernel. + +## Maintainers + +ACPI: Amlal EL Mahrouss. +AHCI: Amlal EL Mahrouss. +CoreCG: Amlal EL Mahrouss. +PS2: Amlal EL Mahrouss. +ATA: Amlal EL Mahrouss. +MBCI: Amlal El Mahrouss. diff --git a/Kernel/Modules/ReadMe.txt b/Kernel/Modules/ReadMe.txt deleted file mode 100644 index ea2bab42..00000000 --- a/Kernel/Modules/ReadMe.txt +++ /dev/null @@ -1,19 +0,0 @@ -============== -Kernel Modules -============== - -=============== -What are these? -=============== - -These are like modules for the kernel. - -=================== -Maintainers/Authors -=================== - -ACPI: Amlal EL Mahrouss. -AHCI: Amlal EL Mahrouss. -CoreCG: Amlal EL Mahrouss. -PS2: Amlal EL Mahrouss. -ATA: Amlal EL Mahrouss. diff --git a/Kernel/Modules/SCSI/SCSI.hxx b/Kernel/Modules/SCSI/SCSI.hxx index ed291ae7..458087ba 100644 --- a/Kernel/Modules/SCSI/SCSI.hxx +++ b/Kernel/Modules/SCSI/SCSI.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Modules/XHCI/Defines.hxx b/Kernel/Modules/XHCI/Defines.hxx index 00c41851..1558ecc1 100644 --- a/Kernel/Modules/XHCI/Defines.hxx +++ b/Kernel/Modules/XHCI/Defines.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: Defines.hxx Purpose: XHCI (and backwards) header. diff --git a/Kernel/NetworkKit/IP.hpp b/Kernel/NetworkKit/IP.hpp index e6ab2e83..80c4ba54 100644 --- a/Kernel/NetworkKit/IP.hpp +++ b/Kernel/NetworkKit/IP.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -8,7 +8,7 @@ #include <KernelKit/DebugOutput.hpp> #include <NewKit/Defines.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> #include <NewKit/String.hpp> namespace Kernel @@ -76,8 +76,8 @@ namespace Kernel class IPFactory final { public: - static ErrorOr<StringView> ToStringView(Ref<RawIPAddress6> ipv6); - static ErrorOr<StringView> ToStringView(Ref<RawIPAddress> ipv4); + static ErrorOr<StringView> ToStringView(Ref<RawIPAddress6>& ipv6); + static ErrorOr<StringView> ToStringView(Ref<RawIPAddress>& ipv4); static bool IpCheckVersion4(const char* ip); }; } // namespace Kernel diff --git a/Kernel/NetworkKit/IPCEP.hxx b/Kernel/NetworkKit/IPCEP.hxx index 48b5b6fd..7a7d8fc9 100644 --- a/Kernel/NetworkKit/IPCEP.hxx +++ b/Kernel/NetworkKit/IPCEP.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation. + Copyright ZKA Technologies. File: IPCEP.hxx. Purpose: IPC protocol. @@ -19,7 +19,7 @@ #define cRemoteSeparator "." /// Interchange address, consists of PID:TEAM. -#define cRemoteInvalid "00:00" +#define cRemoteInvalid "00:00" #define cRemoteHeaderMagic (0x4950434) @@ -59,8 +59,8 @@ namespace Kernel /// @brief IPCEP connection header, message cannot be greater than 6K. typedef struct IPCEPMessageHeader final { - UInt32 IpcHeaderMagic; // cRemoteHeaderMagic - UInt8 IpcEndianess; // 0 : LE, 1 : BE + UInt32 IpcHeaderMagic; // cRemoteHeaderMagic + UInt8 IpcEndianess; // 0 : LE, 1 : BE SizeT IpcPacketSize; IPCEPAddressType IpcFrom; IPCEPAddressType IpcTo; diff --git a/Kernel/NetworkKit/LTE.hxx b/Kernel/NetworkKit/LTE.hxx index cb3aa1e1..37f6f245 100644 --- a/Kernel/NetworkKit/LTE.hxx +++ b/Kernel/NetworkKit/LTE.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation. + Copyright ZKA Technologies. File: LTE.hxx. Purpose: LTE protocol classes. diff --git a/Kernel/NetworkKit/MAC.hxx b/Kernel/NetworkKit/MAC.hxx index 2860f9be..ce718c70 100644 --- a/Kernel/NetworkKit/MAC.hxx +++ b/Kernel/NetworkKit/MAC.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/NetworkKit/NetworkDevice.hpp b/Kernel/NetworkKit/NetworkDevice.hpp index b3e3103e..956475aa 100644 --- a/Kernel/NetworkKit/NetworkDevice.hpp +++ b/Kernel/NetworkKit/NetworkDevice.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/NetworkKit/NetworkDevice.inl b/Kernel/NetworkKit/NetworkDevice.inl index df1b9c81..4f827c3f 100644 --- a/Kernel/NetworkKit/NetworkDevice.inl +++ b/Kernel/NetworkKit/NetworkDevice.inl @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -29,4 +29,4 @@ namespace Kernel if (fCleanup) fCleanup(); } -} // namespace NewOS +} // namespace Kernel diff --git a/Kernel/NetworkKit/compile_flags.txt b/Kernel/NetworkKit/compile_flags.txt index a37ae6bf..39b236a9 100644 --- a/Kernel/NetworkKit/compile_flags.txt +++ b/Kernel/NetworkKit/compile_flags.txt @@ -3,3 +3,4 @@ -std=c++20 -I./ -I../ +-D__ED__ diff --git a/Kernel/NewKit/ApplicationInterface.hxx b/Kernel/NewKit/ApplicationInterface.hxx deleted file mode 100644 index 66737db7..00000000 --- a/Kernel/NewKit/ApplicationInterface.hxx +++ /dev/null @@ -1,31 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -/// -/// @brief Application object, given by the OS to the process. interact with the OS. -/// @file ApplicationInterface.hxx -/// @author Amlal EL Mahrouss -/// - -#include <NewKit/Defines.hpp> -#include <CFKit/GUIDWrapper.hpp> - -/// \brief Application Interface. -/// \author Amlal El Mahrouss -typedef struct _ApplicationInterface final -{ - /// @brief Releases the object exit the process on main object. - Kernel::Void (*Release)(struct _Application* Self, Kernel::Int32 ExitCode); - /// @brief Invoke a function from the application object. - Kernel::IntPtr (*Invoke)(struct _Application* Self, Kernel::Int32 Sel, ...); - /// @brief Query a new application object from a GUID. - /// @note this doesn't query a process, it query a registered object withtin that app. - Kernel::Void (*Query)(struct _Application* Self, Kernel::VoidPtr* Dst, Kernel::SizeT SzDst, Kernel::XRN::GUIDSequence GuidOf); -} ApplicationInterface, *ApplicationInterfaceRef; - -#define app_cast reinterpret_cast<ApplicationInterfaceRef> diff --git a/Kernel/NewKit/Array.hpp b/Kernel/NewKit/Array.hpp index 447d2616..bf630563 100644 --- a/Kernel/NewKit/Array.hpp +++ b/Kernel/NewKit/Array.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #pragma once diff --git a/Kernel/NewKit/ArrayList.hpp b/Kernel/NewKit/ArrayList.hpp index e701f10b..38889a67 100644 --- a/Kernel/NewKit/ArrayList.hpp +++ b/Kernel/NewKit/ArrayList.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/NewKit/Atom.hpp b/Kernel/NewKit/Atom.hpp index 69d485fb..a3e98a4b 100644 --- a/Kernel/NewKit/Atom.hpp +++ b/Kernel/NewKit/Atom.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #pragma once diff --git a/Kernel/NewKit/Crc32.hpp b/Kernel/NewKit/Crc32.hpp index c7d42710..c9c8d311 100644 --- a/Kernel/NewKit/Crc32.hpp +++ b/Kernel/NewKit/Crc32.hpp @@ -2,7 +2,7 @@ * ======================================================== * * Kernel Date Added: 13/02/2023 - * Copyright Zeta Electronics Corporation, all rights reserved. + * Copyright ZKA Technologies, all rights reserved. * * ======================================================== */ diff --git a/Kernel/NewKit/CxxAbi.hpp b/Kernel/NewKit/CxxAbi.hpp index 3f858e21..00d136ec 100644 --- a/Kernel/NewKit/CxxAbi.hpp +++ b/Kernel/NewKit/CxxAbi.hpp @@ -1,13 +1,13 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #pragma once #include <NewKit/Defines.hpp> -#ifdef __GNUC__ +#ifndef __NDK__ #define kDSOMaxObjects (128) @@ -25,4 +25,4 @@ namespace cxxabiv1 typedef void* __guard; } -#endif // __GNUC__
\ No newline at end of file +#endif // __GNUC__ diff --git a/Kernel/NewKit/Defines.hpp b/Kernel/NewKit/Defines.hpp index af8978da..606449ec 100644 --- a/Kernel/NewKit/Defines.hpp +++ b/Kernel/NewKit/Defines.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -133,18 +133,18 @@ namespace Kernel }; } // namespace Kernel -#define DEDUCE_ENDIAN(address, value) \ +#define DEDUCE_ENDIAN(address, value) \ (((reinterpret_cast<Kernel::Char*>(address)[0]) == (value)) \ ? (Kernel::Endian::kEndianBig) \ : (Kernel::Endian::kEndianLittle)) -#define Yes (true) -#define No (false) +#define Yes true +#define No false -#define VoidStar Kernel::voidPtr +#define VoidStar Kernel::VoidPtr -#ifdef INIT -#undef INIT -#endif // ifdef INIT +#ifdef cInitObject +#undef cInitObject +#endif // ifdef cInitObject -#define INIT(OBJ, TYPE, ...) TYPE OBJ = TYPE(__VA_ARGS__) +#define cInitObject(OBJ, TYPE, ...) TYPE OBJ = TYPE(__VA_ARGS__) diff --git a/Kernel/NewKit/ErrorOr.hpp b/Kernel/NewKit/ErrorOr.hpp index 34697d8a..7e261abf 100644 --- a/Kernel/NewKit/ErrorOr.hpp +++ b/Kernel/NewKit/ErrorOr.hpp @@ -2,7 +2,7 @@ * ======================================================== * * Kernel - * Copyright Zeta Electronics Corporation, all rights reserved. + * Copyright ZKA Technologies, all rights reserved. * * ======================================================== */ @@ -10,7 +10,7 @@ #pragma once #include <NewKit/Defines.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> namespace Kernel { @@ -34,7 +34,7 @@ namespace Kernel } explicit ErrorOr(T Class) - : mRef(Class) + : mRef(Class, true) { } diff --git a/Kernel/NewKit/Json.hpp b/Kernel/NewKit/Json.hpp deleted file mode 100644 index b2a0d872..00000000 --- a/Kernel/NewKit/Json.hpp +++ /dev/null @@ -1,118 +0,0 @@ - -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -// last-rev: 30/01/24 - -#include <CompilerKit/CompilerKit.hxx> -#include <NewKit/Defines.hpp> -#include <NewKit/Stream.hpp> -#include <NewKit/String.hpp> -#include <NewKit/Utils.hpp> - -namespace Kernel -{ - /// @brief Json value class - class JsonType final - { - public: - explicit JsonType() - : Kernel::JsonType(1, 1) - { - } - - explicit JsonType(SizeT lhsLen, SizeT rhsLen) - : fKey(lhsLen), fValue(rhsLen) - { - } - - ~JsonType() = default; - - NEWOS_COPY_DEFAULT(JsonType); - - private: - StringView fKey; - StringView fValue; - - public: - /// @brief returns the key of the json - /// @return the key as string view. - StringView& AsKey() - { - return fKey; - } - - /// @brief returns the value of the json. - /// @return the key as string view. - StringView& AsValue() - { - return fValue; - } - - static JsonType kUndefined; - }; - - /// @brief Json stream helper class. - struct JsonStreamTrait final - { - JsonType In(const char* full_array) - { - SizeT len = rt_string_len(full_array); - - if (full_array[0] == '\"' && full_array[len - 1] == ',' || - full_array[len - 1] == '\"') - { - Boolean probe_key = true; - - SizeT key_len = 0; - SizeT value_len = 0; - - for (SizeT i = 1; i < len; i++) - { - if (full_array[i] == ' ') - continue; - - JsonType type(kPathLen, kPathLen); - - if (probe_key) - { - type.AsKey().Data()[key_len] = full_array[i]; - ++key_len; - - if (full_array[i] == '\"') - { - probe_key = false; - type.AsKey().Data()[key_len] = 0; - - ++i; - } - } - else - { - type.AsValue().Data()[value_len] = full_array[i]; - ++value_len; - - if (full_array[i] == '\"') - { - type.AsValue().Data()[value_len] = 0; - } - } - } - } - - return JsonType::kUndefined; - } - - JsonType Out(JsonType& out) - { - return out; - } - }; - - using JsonStream = Stream<JsonStreamTrait, JsonType>; -} // namespace Kernel diff --git a/Kernel/NewKit/Json.hxx b/Kernel/NewKit/Json.hxx new file mode 100644 index 00000000..9371bf15 --- /dev/null +++ b/Kernel/NewKit/Json.hxx @@ -0,0 +1,134 @@ + +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +// last-rev: 30/01/24 + +#include <CompilerKit/CompilerKit.hxx> +#include <NewKit/Defines.hpp> +#include <NewKit/Stream.hpp> +#include <NewKit/String.hpp> +#include <NewKit/Utils.hpp> + +#define cMaxJsonPath 4096 +#define cJSONLen 32 +#define cJSONNull "null" + +namespace Kernel +{ + /// @brief Json value class + class JsonType final + { + public: + explicit JsonType() + { + auto len = cJSONLen; + StringView key = StringView(len); + key += cJSONNull; + + this->AsKey() = key; + this->AsValue() = key; + } + + explicit JsonType(SizeT lhsLen, SizeT rhsLen) + : fKey(lhsLen), fValue(rhsLen) + { + } + + ~JsonType() = default; + + NEWOS_COPY_DEFAULT(JsonType); + + const Bool& IsUndefined() { return fUndefined; } + + private: + Bool fUndefined; // is this instance undefined? + StringView fKey; + StringView fValue; + + public: + /// @brief returns the key of the json + /// @return the key as string view. + StringView& AsKey() + { + return fKey; + } + + /// @brief returns the value of the json. + /// @return the key as string view. + StringView& AsValue() + { + return fValue; + } + + static JsonType kNull; + }; + + /// @brief Json stream reader helper. + struct JsonStreamReader final + { + STATIC JsonType In(const Char* full_array) + { + if (full_array[0] != '{') + return JsonType::kNull; + + SizeT len = rt_string_len(full_array); + Boolean probe_value = false; + + SizeT key_len = 0; + SizeT value_len = 0; + + JsonType type(cMaxJsonPath, cMaxJsonPath); + + for (SizeT i = 1; i < len; ++i) + { + if (full_array[i] == '\r' || + full_array[i] == '\n') + continue; + + if (probe_value) + { + if (full_array[i] == '}' || + full_array[i] == ',') + { + probe_value = false; + + ++value_len; + } + else + { + type.AsValue().Data()[value_len] = full_array[i]; + + ++value_len; + } + } + else + { + if (full_array[i] == ':') + { + probe_value = true; + type.AsKey().Data()[key_len] = 0; + ++key_len; + } + else + { + type.AsKey().Data()[key_len] = full_array[i]; + + ++key_len; + } + } + } + + type.AsValue().Data()[value_len] = 0; + + return type; + } + }; + + using JsonStream = Stream<JsonStreamReader, JsonType>; +} // namespace Kernel diff --git a/Kernel/NewKit/KernelCheck.hpp b/Kernel/NewKit/KernelCheck.hpp index ae1eec51..ed74e38f 100644 --- a/Kernel/NewKit/KernelCheck.hpp +++ b/Kernel/NewKit/KernelCheck.hpp @@ -1,7 +1,7 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -40,13 +40,11 @@ enum RUNTIME_CHECK namespace Kernel { - class DumpManager final + /// @brief Dumping factory class. + class RecoveryFactory final { public: - static void Dump(void) - { - // TODO: - } + STATIC Void Recover() noexcept; }; void ke_stop(const Int& id); diff --git a/Kernel/NewKit/Macros.hpp b/Kernel/NewKit/Macros.hpp index 1f121a37..ba636874 100644 --- a/Kernel/NewKit/Macros.hpp +++ b/Kernel/NewKit/Macros.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -10,18 +10,34 @@ #define KIB(X) ((X) / 1024) #endif +#ifndef kib_cast +#define kib_cast(X) ((X) * 1024) +#endif + #ifndef MIB #define MIB(X) ((UInt64)KIB(X) / 1024) #endif +#ifndef mib_cast +#define mib_cast(X) ((UInt64)kib_cast(X) * 1024) +#endif + #ifndef GIB #define GIB(X) ((UInt64)MIB(X) / 1024) #endif +#ifndef gib_cast +#define gib_cast(X) ((UInt64)mib_cast(X) * 1024) +#endif + #ifndef TIB #define TIB(X) ((UInt64)GIB(X) / 1024) #endif +#ifndef tib_cast +#define tib_cast(X) ((UInt64)gib_cast(X) * 1024) +#endif + #ifndef ARRAY_SIZE #define ARRAY_SIZE(a) \ (((sizeof(a) / sizeof(*(a))) / \ @@ -37,7 +53,7 @@ #endif // #ifndef ATTRIBUTE #ifndef __MAHROUSS__ -#define __MAHROUSS__ (202401) +#define __MAHROUSS__ (202404) #endif // !__MAHROUSS__ #ifndef EXTERN_C @@ -63,16 +79,16 @@ #endif #ifndef ENUM_STRING -#define ENUM_STRING(NAME, VAL) inline constexpr const char* NAME = VAL +#define ENUM_STRING(NAME, VAL) inline constexpr const char* e##NAME = VAL #endif #ifndef END_STRING_ENUM #define END_STRING_ENUM() } #endif -#ifndef Alloca -#define Alloca(Sz) __builtin_alloca(Sz) -#endif // #ifndef Alloca +#ifndef ALLOCA +#define ALLOCA(Sz) __builtin_alloca(Sz) +#endif // #ifndef ALLOCA #ifndef CANT_REACH #define CANT_REACH() __builtin_unreachable() @@ -91,8 +107,8 @@ #define CONST const #define STRINGIFY(X) #X -#define NEWOS_UNUSED(X) ((void)X) +#define NEWOS_UNUSED(X) ((Kernel::Void)X) #ifndef RGB -#define RGB(R, G, B) (UInt32)(0x##R##G##B) +#define RGB(R, G, B) (Kernel::UInt32)(R | G << 0x8 | B << 0x10) #endif // !RGB diff --git a/Kernel/NewKit/MutableArray.hpp b/Kernel/NewKit/MutableArray.hpp index 6f30b0f9..58038e8f 100644 --- a/Kernel/NewKit/MutableArray.hpp +++ b/Kernel/NewKit/MutableArray.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #pragma once diff --git a/Kernel/NewKit/New.hpp b/Kernel/NewKit/New.hpp index 33e5c163..eade355d 100644 --- a/Kernel/NewKit/New.hpp +++ b/Kernel/NewKit/New.hpp @@ -1,12 +1,12 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #pragma once -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> typedef __SIZE_TYPE__ size_t; // gcc will complain about that diff --git a/Kernel/NewKit/NewKit.hpp b/Kernel/NewKit/NewKit.hpp index bf04eb0b..144a0ea9 100644 --- a/Kernel/NewKit/NewKit.hpp +++ b/Kernel/NewKit/NewKit.hpp @@ -1,7 +1,7 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -10,13 +10,13 @@ #include <NewKit/Array.hpp> #include <NewKit/ArrayList.hpp> #include <NewKit/ErrorOr.hpp> -#include <NewKit/Json.hpp> +#include <NewKit/Json.hxx> #include <NewKit/KernelCheck.hpp> #include <KernelKit/LockDelegate.hpp> #include <NewKit/MutableArray.hpp> #include <NewKit/New.hpp> #include <NewKit/OwnPtr.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> #include <NewKit/Stream.hpp> -#include <KernelKit/UserHeap.hpp> +#include <KernelKit/ProcessHeap.hxx> #include <NewKit/Utils.hpp> diff --git a/Kernel/NewKit/OwnPtr.hpp b/Kernel/NewKit/OwnPtr.hpp index 2d7cf65b..6157a1b6 100644 --- a/Kernel/NewKit/OwnPtr.hpp +++ b/Kernel/NewKit/OwnPtr.hpp @@ -1,7 +1,7 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -9,7 +9,7 @@ #include <NewKit/Defines.hpp> #include <NewKit/KernelCheck.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> namespace Kernel { diff --git a/Kernel/NewKit/PageAllocator.hpp b/Kernel/NewKit/PageAllocator.hpp index 40da5129..f7697488 100644 --- a/Kernel/NewKit/PageAllocator.hpp +++ b/Kernel/NewKit/PageAllocator.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/NewKit/PageManager.hpp b/Kernel/NewKit/PageManager.hpp index 233ced0a..57b842ba 100644 --- a/Kernel/NewKit/PageManager.hpp +++ b/Kernel/NewKit/PageManager.hpp @@ -3,7 +3,7 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -11,7 +11,7 @@ #include <NewKit/Defines.hpp> #include <NewKit/PageAllocator.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> #ifndef kBadAddress #define kBadAddress (0) diff --git a/Kernel/NewKit/Pair.hpp b/Kernel/NewKit/Pair.hpp index 7a7df020..2cf89f59 100644 --- a/Kernel/NewKit/Pair.hpp +++ b/Kernel/NewKit/Pair.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/NewKit/Pmm.hpp b/Kernel/NewKit/Pmm.hpp index fc020fea..46db1879 100644 --- a/Kernel/NewKit/Pmm.hpp +++ b/Kernel/NewKit/Pmm.hpp @@ -1,14 +1,14 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #pragma once #include <NewKit/PageManager.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> namespace Kernel { diff --git a/Kernel/NewKit/Ref.hpp b/Kernel/NewKit/Ref.hxx index 0d5550fa..69150054 100644 --- a/Kernel/NewKit/Ref.hpp +++ b/Kernel/NewKit/Ref.hxx @@ -1,11 +1,12 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#pragma once +#ifndef _NEWKIT_REF_HPP_ +#define _NEWKIT_REF_HPP_ #include <NewKit/Defines.hpp> #include <NewKit/KernelCheck.hpp> @@ -17,34 +18,47 @@ namespace Kernel { public: Ref() = default; - ~Ref() = default; + + ~Ref() + { + if (fStrong) + { + fClass = nullptr; + } + } public: Ref(T cls, const bool& strong = false) - : fClass(cls), fStrong(strong) + : fClass(&cls), fStrong(strong) { } Ref& operator=(T ref) { - fClass = ref; + *fClass = ref; return *this; } public: T operator->() const { - return fClass; + return *fClass; } - T& Leak() + T& Leak() noexcept { - return fClass; + return *fClass; + } + + T& TryLeak() const noexcept + { + MUST_PASS(*fClass); + return *fClass; } T operator*() { - return fClass; + return *fClass; } bool IsStrong() const @@ -52,14 +66,14 @@ namespace Kernel return fStrong; } - operator bool() + operator bool() noexcept { return fStrong; } private: - T fClass; - bool fStrong{false}; + T* fClass; + Bool fStrong{false}; }; template <typename T> @@ -72,6 +86,7 @@ namespace Kernel NonNullRef(T* ref) : fRef(ref, true) { + MUST_PASS(ref != nullptr); } Ref<T>& operator->() @@ -87,3 +102,5 @@ namespace Kernel Ref<T> fRef{nullptr}; }; } // namespace Kernel + +#endif // ifndef _NEWKIT_REF_HPP_ diff --git a/Kernel/NewKit/Stream.hpp b/Kernel/NewKit/Stream.hpp index bd64910e..eefb0a1c 100644 --- a/Kernel/NewKit/Stream.hpp +++ b/Kernel/NewKit/Stream.hpp @@ -1,14 +1,14 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #pragma once #include <NewKit/Defines.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> namespace Kernel { diff --git a/Kernel/NewKit/String.hpp b/Kernel/NewKit/String.hpp index f9ab9aa4..7440900c 100644 --- a/Kernel/NewKit/String.hpp +++ b/Kernel/NewKit/String.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -8,6 +8,7 @@ #include <NewKit/Defines.hpp> #include <NewKit/ErrorOr.hpp> +#include <NewKit/Utils.hpp> #include <NewKit/KernelCheck.hpp> namespace Kernel @@ -15,7 +16,15 @@ namespace Kernel class StringView final { public: - explicit StringView() = default; + explicit StringView() + { + fSz = 4096; + + fData = new Char[fSz]; + MUST_PASS(fData); + + rt_set_memory(fData, 0, fSz); + } explicit StringView(Size Sz) : fSz(Sz) @@ -23,6 +32,8 @@ namespace Kernel MUST_PASS(Sz > 1); fData = new Char[Sz]; MUST_PASS(fData); + + rt_set_memory(fData, 0, Sz); } ~StringView() diff --git a/Kernel/NewKit/Utils.hpp b/Kernel/NewKit/Utils.hpp index 22192135..32749560 100644 --- a/Kernel/NewKit/Utils.hpp +++ b/Kernel/NewKit/Utils.hpp @@ -1,7 +1,7 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/NewKit/Variant.hpp b/Kernel/NewKit/Variant.hpp index ee14216a..c118eda1 100644 --- a/Kernel/NewKit/Variant.hpp +++ b/Kernel/NewKit/Variant.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -8,6 +8,7 @@ #include <NewKit/Defines.hpp> #include <NewKit/String.hpp> +#include <NewKit/Json.hxx> namespace Kernel { @@ -17,8 +18,9 @@ namespace Kernel enum class VariantKind { kString, - kPointer, - kUndefined + kBlob, + kNull, + kJson, }; public: @@ -35,20 +37,28 @@ namespace Kernel : fPtr((voidPtr)stringView), fKind(VariantKind::kString) { } + + explicit Variant(JsonType* json) + : fPtr((voidPtr)json), fKind(VariantKind::kJson) + { + } + explicit Variant(nullPtr) - : fPtr(nullptr), fKind(VariantKind::kUndefined) + : fPtr(nullptr), fKind(VariantKind::kNull) { } + explicit Variant(voidPtr ptr) - : fPtr(ptr), fKind(VariantKind::kPointer) + : fPtr(ptr), fKind(VariantKind::kBlob) { } public: const Char* ToString(); + VoidPtr Leak(); private: voidPtr fPtr{nullptr}; - VariantKind fKind{VariantKind::kUndefined}; + VariantKind fKind{VariantKind::kNull}; }; } // namespace Kernel diff --git a/Kernel/Sources/Array.cxx b/Kernel/Sources/Array.cxx index 2b1cb7db..40f38c00 100644 --- a/Kernel/Sources/Array.cxx +++ b/Kernel/Sources/Array.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/ArrayList.cxx b/Kernel/Sources/ArrayList.cxx index 1e12e714..2553710a 100644 --- a/Kernel/Sources/ArrayList.cxx +++ b/Kernel/Sources/ArrayList.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Atom.cxx b/Kernel/Sources/Atom.cxx index b79c1122..48526674 100644 --- a/Kernel/Sources/Atom.cxx +++ b/Kernel/Sources/Atom.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/CodeManager.cxx b/Kernel/Sources/CodeManager.cxx index 91b6c99e..3830e922 100644 --- a/Kernel/Sources/CodeManager.cxx +++ b/Kernel/Sources/CodeManager.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Crc32.cxx b/Kernel/Sources/Crc32.cxx index 8c555dc5..03eb4589 100644 --- a/Kernel/Sources/Crc32.cxx +++ b/Kernel/Sources/Crc32.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/CxxAbi.cxx b/Kernel/Sources/CxxAbi-AMD64.cxx index febffbc4..e1f61aaf 100644 --- a/Kernel/Sources/CxxAbi.cxx +++ b/Kernel/Sources/CxxAbi-AMD64.cxx @@ -1,9 +1,11 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ +#ifdef __NEWOS_AMD64__ + #include <KernelKit/DebugOutput.hpp> #include <NewKit/CxxAbi.hpp> #include <KernelKit/HError.hpp> @@ -20,17 +22,12 @@ EXTERN_C void __cxa_pure_virtual() Kernel::kcout << "newoskrnl: C++ placeholder method.\n"; } -EXTERN_C void ___chkstk_ms() +EXTERN_C void ___chkstk_ms(void) { Kernel::err_bug_check_raise(); Kernel::err_bug_check(); } -#ifdef __NEWOS_ARM64__ -// AEABI specific. -#define atexit __aeabi_atexit -#endif - EXTERN_C int atexit(void (*f)(void*), void* arg, void* dso) { if (__atexit_func_count >= kDSOMaxObjects) @@ -90,3 +87,5 @@ namespace cxxabiv1 (void)g; } } // namespace cxxabiv1 + +#endif // ifdef __NEWOS_AMD64__ diff --git a/Kernel/Sources/CxxAbi-ARM64.cxx b/Kernel/Sources/CxxAbi-ARM64.cxx new file mode 100644 index 00000000..46524374 --- /dev/null +++ b/Kernel/Sources/CxxAbi-ARM64.cxx @@ -0,0 +1,74 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#ifdef __NEWOS_ARM64__ + +#include <KernelKit/DebugOutput.hpp> +#include <NewKit/CxxAbi.hpp> +#include <KernelKit/HError.hpp> + +EXTERN_C +{ +#include <limits.h> +} + +int const cUninitialized = 0; +int const cBeingInitialized = -1; +int const cEpochStart = INT_MIN; + +EXTERN_C +{ + int _Init_global_epoch = cEpochStart; + __thread int _Init_thread_epoch = cEpochStart; +} + +Kernel::UInt32 const cNKTimeout = 100; // ms + +EXTERN_C void __cdecl _Init_thread_wait(Kernel::UInt32 const timeout) +{ + MUST_PASS(timeout != INT_MAX); +} + +EXTERN_C void __cdecl _Init_thread_header(int* const pOnce) noexcept +{ + if (*pOnce == cUninitialized) + { + *pOnce = cBeingInitialized; + } + else + { + while (*pOnce == cBeingInitialized) + { + _Init_thread_wait(cNKTimeout); + + if (*pOnce == cUninitialized) + { + *pOnce = cBeingInitialized; + return; + } + } + _Init_thread_epoch = _Init_global_epoch; + } +} + +EXTERN_C void __cdecl _Init_thread_abort(int* const pOnce) noexcept +{ + *pOnce = cUninitialized; +} + +EXTERN_C void __cdecl _Init_thread_footer(int* const pOnce) noexcept +{ + ++_Init_global_epoch; + *pOnce = _Init_global_epoch; + _Init_thread_epoch = _Init_global_epoch; +} + +EXTERN_C void _purecall() +{ + Kernel::kcout << "newoskrnl: C++ placeholder method.\n"; +} + +#endif // ifdef __NEWOS_ARM64__ diff --git a/Kernel/Sources/Defines.cxx b/Kernel/Sources/Defines.cxx index aa39adef..0f90f909 100644 --- a/Kernel/Sources/Defines.cxx +++ b/Kernel/Sources/Defines.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/DeviceManager.cxx b/Kernel/Sources/DeviceManager.cxx index f729c419..b3e5f0c5 100644 --- a/Kernel/Sources/DeviceManager.cxx +++ b/Kernel/Sources/DeviceManager.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/DriveManager.cxx b/Kernel/Sources/DriveManager.cxx index 039a4e00..58a822e1 100644 --- a/Kernel/Sources/DriveManager.cxx +++ b/Kernel/Sources/DriveManager.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/ErrorOr.cxx b/Kernel/Sources/ErrorOr.cxx index 94366447..077f1550 100644 --- a/Kernel/Sources/ErrorOr.cxx +++ b/Kernel/Sources/ErrorOr.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx index 1eef02d8..38a417cb 100644 --- a/Kernel/Sources/FS/NewFS.cxx +++ b/Kernel/Sources/FS/NewFS.cxx @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ #include <Modules/AHCI/AHCI.hxx> #include <Modules/ATA/ATA.hxx> @@ -20,15 +20,29 @@ using namespace Kernel; +#ifdef __ED__ +/** + Define those external symbols, to make the editor shutup +*/ + +/// @brief get sector count. +Kernel::SizeT drv_std_get_sector_count(); + +/// @brief get device size. +Kernel::SizeT drv_std_get_drv_size(); + +#endif + + ///! BUGS: 0 /***********************************************************************************/ /// This file implements the New File System. /// New File System implements a B-Tree based algortihm. -/// /Disk -/// /Path1 /Path2 -/// /File.txt /File.pef /File.png <-- symlink. -/// /Path1/File.txt +/// \\ +/// \\Path1\\ \\ath2\\ +/// \\readme.rtf \\ListContents.pef \\readme.lnk <-- symlink. +/// \\Path1\\readme.rtf /***********************************************************************************/ STATIC MountpointInterface sMountpointInterface; @@ -37,8 +51,8 @@ STATIC MountpointInterface sMountpointInterface; /// @param catalog it's catalog /// @param theFork the fork itself. /// @return the fork -_Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, - _Input NewFork& theFork) +_Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input NFS_FORK_STRUCT& theFork) { if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr; @@ -60,8 +74,8 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, rt_copy_memory((VoidPtr) "fs/newfs-packet", drv->fPacket.fPacketMime, rt_string_len("fs/newfs-packet")); - NewFork curFork{0}; - NewFork prevFork{0}; + NFS_FORK_STRUCT curFork{0}; + NFS_FORK_STRUCT prevFork{0}; Lba lbaOfPreviousFork = lba; /// do not check for anything. Loop until we get what we want, that is a free fork zone. @@ -71,7 +85,7 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, break; drv->fPacket.fLba = lba; - drv->fPacket.fPacketSize = sizeof(NewFork); + drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drv->fPacket.fPacketContent = &curFork; drv->fInput(&drv->fPacket); @@ -101,7 +115,7 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, if (lba >= kNewFSCatalogStartAddress) { drv->fPacket.fLba = lbaOfPreviousFork; - drv->fPacket.fPacketSize = sizeof(NewFork); + drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drv->fPacket.fPacketContent = &prevFork; prevFork.NextSibling = lba; @@ -118,12 +132,12 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, 4; /// this value gives us space for the data offset. theFork.Flags = kNewFSFlagCreated; - theFork.DataOffset = lba - sizeof(NewFork) * cForkPadding; + theFork.DataOffset = lba - sizeof(NFS_FORK_STRUCT) * cForkPadding; theFork.PreviousSibling = lbaOfPreviousFork; theFork.NextSibling = theFork.DataOffset - theFork.DataSize; drv->fPacket.fLba = lba; - drv->fPacket.fPacketSize = sizeof(NewFork); + drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drv->fPacket.fPacketContent = &theFork; drv->fOutput(&drv->fPacket); @@ -144,19 +158,19 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, /// @param catalog the catalog. /// @param name the fork name. /// @return the fork. -_Output NewFork* NewFSParser::FindFork(_Input NewCatalog* catalog, +_Output NFS_FORK_STRUCT* NewFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog, _Input const Char* name, Boolean isDataFork) { auto drv = sMountpointInterface.GetAddressOf(this->fDriveIndex); - NewFork* theFork = nullptr; + NFS_FORK_STRUCT* theFork = nullptr; Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork; while (lba != 0) { drv->fPacket.fLba = lba; - drv->fPacket.fPacketSize = sizeof(NewFork); + drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drv->fPacket.fPacketContent = (VoidPtr)theFork; rt_copy_memory((VoidPtr) "fs/newfs-packet", drv->fPacket.fPacketMime, 16); @@ -197,7 +211,7 @@ _Output NewFork* NewFSParser::FindFork(_Input NewCatalog* catalog, /// file.) /// @param name /// @return catalog pointer. -_Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name) +_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const char* name) { return this->CreateCatalog(name, 0, kNewFSCatalogKindFile); } @@ -207,7 +221,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name) /// @param flags the flags of the catalog. /// @param kind the catalog kind. /// @return catalog pointer. -_Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, +_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const char* name, _Input const Int32& flags, _Input const Int32& kind) { @@ -226,7 +240,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, name[rt_string_len(name) - 1] == NewFilesystemHelper::Separator()) return nullptr; - NewCatalog* copyExists = this->FindCatalog(name, outLba); + NFS_CATALOG_STRUCT* copyExists = this->FindCatalog(name, outLba); if (copyExists) { @@ -270,7 +284,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, --indexReverseCopy; } - NewCatalog* catalog = this->FindCatalog(parentName, outLba); + NFS_CATALOG_STRUCT* catalog = this->FindCatalog(parentName, outLba); if (catalog && catalog->Kind == kNewFSCatalogKindFile) { @@ -284,7 +298,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, constexpr SizeT cDefaultForkSize = kNewFSForkSize; - NewCatalog* catalogChild = new NewCatalog(); + NFS_CATALOG_STRUCT* catalogChild = new NFS_CATALOG_STRUCT(); catalogChild->ResourceForkSize = cDefaultForkSize; catalogChild->DataForkSize = cDefaultForkSize; @@ -312,7 +326,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, drive->fInput(&drive->fPacket); - NewCatalog* nextSibling = (NewCatalog*)catalogBuf; + NFS_CATALOG_STRUCT* nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf; startFree = nextSibling->NextSibling; @@ -323,7 +337,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, while (drive->fPacket.fPacketGood) { - nextSibling = (NewCatalog*)catalogBuf; + nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf; if (startFree <= kNewFSStartLba) { @@ -346,7 +360,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, constexpr auto cNewFSCatalogPadding = 4; - NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBufPartBlock; + NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; if (partBlock->FreeCatalog < 1) { @@ -359,10 +373,10 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, catalogChild->ResourceFork = catalogChild->DataFork; catalogChild->NextSibling = - startFree + (sizeof(NewCatalog) * cNewFSCatalogPadding); + startFree + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); drive->fPacket.fPacketContent = catalogChild; - drive->fPacket.fPacketSize = sizeof(NewCatalog); + drive->fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); drive->fPacket.fLba = startFree; drive->fOutput(&drive->fPacket); @@ -370,7 +384,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, drive->fPacket.fPacketContent = catalogBuf; drive->fPacket.fPacketSize = kNewFSSectorSz; drive->fPacket.fLba = - startFree - (sizeof(NewCatalog) * cNewFSCatalogPadding); + startFree - (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); drive->fInput(&drive->fPacket); @@ -403,7 +417,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, constexpr auto cNewFSCatalogPadding = 4; //// @note that's how we find the next catalog in the partition block. - startFree = startFree + (sizeof(NewCatalog) * cNewFSCatalogPadding); + startFree = startFree + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); drive->fPacket.fPacketContent = catalogBuf; drive->fPacket.fPacketSize = kNewFSSectorSz; @@ -445,13 +459,13 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) /// disk isnt faulty and data has been fetched. if (drive->fPacket.fPacketGood) { - NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBuf; + NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBuf; /// check for an empty partition here. if (partBlock->PartitionName[0] == 0 && rt_string_cmp(partBlock->Ident, kNewFSIdent, kNewFSIdentLen)) { - /// partition is free and valid. + // partition is free and valid. partBlock->Version = kNewFSVersionInteger; @@ -463,17 +477,18 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) rt_copy_memory((VoidPtr)cUntitledHD, (VoidPtr)partBlock->PartitionName, rt_string_len(cUntitledHD)); - SizeT catalogCount = 0; - SizeT sectorCount = drv_std_get_sector_count(); - SizeT diskSize = drv_std_get_drv_size(); + SizeT catalogCount = 0UL; + + SizeT sectorCount = drv_std_get_sector_count(); + SizeT diskSize = drv_std_get_drv_size(); partBlock->Kind = kNewFSPartitionTypeStandard; partBlock->StartCatalog = kNewFSCatalogStartAddress; partBlock->Flags = kNewFSPartitionTypeStandard; - partBlock->CatalogCount = sectorCount / sizeof(NewCatalog); + partBlock->CatalogCount = sectorCount / sizeof(NFS_CATALOG_STRUCT); partBlock->SectorCount = sectorCount; partBlock->DiskSize = diskSize; - partBlock->FreeCatalog = sectorCount / sizeof(NewCatalog); + partBlock->FreeCatalog = sectorCount / sizeof(NFS_CATALOG_STRUCT); drive->fPacket.fPacketContent = sectorBuf; drive->fPacket.fPacketSize = kNewFSSectorSz; @@ -490,15 +505,15 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) kcout << "newoskrnl: free sectors: " << hex_number(partBlock->FreeSectors) << endl; kcout << "newoskrnl: sector size: " << hex_number(partBlock->SectorSize) << endl; - /// write the root catalog. + // write the root catalog. this->CreateCatalog(kNewFSRoot, 0, kNewFSCatalogKindDir); if (partBlock->Flags & kNewFSPartitionTypeBoot) { - /// make it bootable when needed. + // make it bootable when needed. Char bufEpmHdr[kNewFSSectorSz] = {0}; - BootBlockType* epmBoot = (BootBlockType*)bufEpmHdr; + BOOT_BLOCK_STRUCT* epmBoot = (BOOT_BLOCK_STRUCT*)bufEpmHdr; constexpr auto cFsName = "NewFS"; constexpr auto cBlockName = "Zeta:"; @@ -525,7 +540,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) kcout << "newoskrnl: partition block already exists.\r"; - /// return success as well, do not ignore that partition. + // return success as well, do not ignore that partition. return true; } @@ -536,15 +551,15 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) /// @param catalog the catalog itself /// @param data the data. /// @return if the catalog w rote the contents successfully. -bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, SizeT sizeOfData, _Input const char* forkName) +bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, voidPtr data, SizeT sizeOfData, _Input const char* forkName) { if (sizeOfData > catalog->DataForkSize) return false; if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return false; - NewFork* forkData = new NewFork(); - rt_set_memory(forkData, 0, sizeof(NewFork)); + NFS_FORK_STRUCT* forkData = new NFS_FORK_STRUCT(); + rt_set_memory(forkData, 0, sizeof(NFS_FORK_STRUCT)); auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); @@ -555,18 +570,18 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, rt_copy_memory(catalog->Name, forkData->CatalogName, kNewFSNodeNameLen); - /// sanity check of the fork position as the condition to run the loop. + // sanity check of the fork position as the condition to run the loop. while (startFork >= kNewFSCatalogStartAddress) { drive->fPacket.fPacketContent = forkData; - drive->fPacket.fPacketSize = sizeof(NewFork); + drive->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drive->fPacket.fLba = startFork; drive->fInput(&drive->fPacket); kcout << "newoskrnl: fork name: " << forkData->ForkName << endl; - /// sanity check the fork. + // check the fork, if it's position is valid. if (forkData->DataOffset <= kNewFSCatalogStartAddress) { ErrLocal() = kErrorDiskIsCorrupted; @@ -620,7 +635,7 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, /// @brief /// @param catalogName the catalog name. /// @return the newly found catalog. -_Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, +_Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const char* catalogName, Lba& outLba) { if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) @@ -628,19 +643,19 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, kcout << "newoskrnl: start finding catalog...\r"; - Char* sectorBuf = new Char[sizeof(NewPartitionBlock)]; + Char* sectorBuf = new Char[sizeof(NFS_ROOT_PARTITION_BLOCK)]; auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime, rt_string_len("fs/newfs-packet")); drive->fPacket.fPacketContent = sectorBuf; - drive->fPacket.fPacketSize = sizeof(NewPartitionBlock); + drive->fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); drive->fPacket.fLba = kNewFSStartLba; drive->fInput(&drive->fPacket); - NewPartitionBlock* part = (NewPartitionBlock*)sectorBuf; + NFS_ROOT_PARTITION_BLOCK* part = (NFS_ROOT_PARTITION_BLOCK*)sectorBuf; auto startCatalogList = part->StartCatalog; const auto cCtartCatalogList = part->StartCatalog; @@ -649,7 +664,7 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, drive->fPacket.fLba = startCatalogList; drive->fPacket.fPacketContent = sectorBuf; - drive->fPacket.fPacketSize = sizeof(NewCatalog); + drive->fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); drive->fInput(&drive->fPacket); @@ -676,7 +691,7 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, --indexReverseCopy; } - NewCatalog* parentCatalog = this->FindCatalog(parentName, outLba); + NFS_CATALOG_STRUCT* parentCatalog = this->FindCatalog(parentName, outLba); if (parentCatalog && !StringBuilder::Equals(parentName, NewFilesystemHelper::Root())) @@ -697,7 +712,7 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, _NewFSSearchThroughCatalogList: while (drive->fPacket.fPacketGood) { - NewCatalog* catalog = (NewCatalog*)sectorBuf; + NFS_CATALOG_STRUCT* catalog = (NFS_CATALOG_STRUCT*)sectorBuf; if (StringBuilder::Equals(catalogName, catalog->Name)) { @@ -707,8 +722,8 @@ _NewFSSearchThroughCatalogList: goto _NewFSContinueSearch; } - NewCatalog* catalogPtr = new NewCatalog(); - rt_copy_memory(catalog, catalogPtr, sizeof(NewCatalog)); + NFS_CATALOG_STRUCT* catalogPtr = new NFS_CATALOG_STRUCT(); + rt_copy_memory(catalog, catalogPtr, sizeof(NFS_CATALOG_STRUCT)); kcout << "newoskrnl: found catalog at: " << hex_number(startCatalogList) << endl; @@ -725,7 +740,7 @@ _NewFSSearchThroughCatalogList: drive->fPacket.fLba = startCatalogList; drive->fPacket.fPacketContent = sectorBuf; - drive->fPacket.fPacketSize = sizeof(NewCatalog); + drive->fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); drive->fInput(&drive->fPacket); } @@ -747,7 +762,7 @@ _NewFSSearchThroughCatalogList: /// @brief /// @param name /// @return -_Output NewCatalog* NewFSParser::GetCatalog(_Input const char* name) +_Output NFS_CATALOG_STRUCT* NewFSParser::GetCatalog(_Input const char* name) { Lba unused = 0; return this->FindCatalog(name, unused); @@ -756,7 +771,7 @@ _Output NewCatalog* NewFSParser::GetCatalog(_Input const char* name) /// @brief /// @param catalog /// @return -Boolean NewFSParser::CloseCatalog(_Input _Output NewCatalog* catalog) +Boolean NewFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog) { if (!catalog) return false; @@ -794,21 +809,21 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) drive->fPacket.fLba = outLba; // the catalog position. drive->fPacket.fPacketSize = - sizeof(NewCatalog); // size of catalog. roughly the sector size. + sizeof(NFS_CATALOG_STRUCT); // size of catalog. roughly the sector size. drive->fPacket.fPacketContent = catalog; // the catalog itself. drive->fOutput(&drive->fPacket); // send packet. - Char partitionBlockBuf[sizeof(NewPartitionBlock)] = {0}; + Char partitionBlockBuf[sizeof(NFS_ROOT_PARTITION_BLOCK)] = {0}; drive->fPacket.fLba = kNewFSStartLba; drive->fPacket.fPacketContent = partitionBlockBuf; - drive->fPacket.fPacketSize = sizeof(NewPartitionBlock); + drive->fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); drive->fInput(&drive->fPacket); - NewPartitionBlock* partBlock = - reinterpret_cast<NewPartitionBlock*>(partitionBlockBuf); + NFS_ROOT_PARTITION_BLOCK* partBlock = + reinterpret_cast<NFS_ROOT_PARTITION_BLOCK*>(partitionBlockBuf); ++partBlock->FreeCatalog; --partBlock->CatalogCount; @@ -833,7 +848,7 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) /// @return /***********************************************************************************/ -VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, +VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, _Input SizeT dataSz, _Input const char* forkName) { @@ -852,23 +867,23 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, kcout << "newoskrnl: catalog " << catalog->Name << ", fork: " << hex_number(dataForkLba) << endl; - Char* sectorBuf = new Char[sizeof(NewFork)]; + Char* sectorBuf = new Char[sizeof(NFS_FORK_STRUCT)]; auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime, rt_string_len("fs/newfs-packet")); - NewFork* forkData = nullptr; + NFS_FORK_STRUCT* forkData = nullptr; while (dataForkLba >= kNewFSCatalogStartAddress) { drive->fPacket.fLba = dataForkLba; - drive->fPacket.fPacketSize = sizeof(NewFork); + drive->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drive->fPacket.fPacketContent = sectorBuf; drive->fInput(&drive->fPacket); - forkData = (NewFork*)sectorBuf; + forkData = (NFS_FORK_STRUCT*)sectorBuf; kcout << "newoskrnl: name: " << forkData->ForkName << endl; @@ -913,7 +928,7 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, /// @return if the seeking was successful. /***********************************************************************************/ -bool NewFSParser::Seek(_Input _Output NewCatalog* catalog, SizeT off) +bool NewFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off) { if (!catalog) { @@ -931,7 +946,7 @@ bool NewFSParser::Seek(_Input _Output NewCatalog* catalog, SizeT off) /// @return The position on the file. /***********************************************************************************/ -SizeT NewFSParser::Tell(_Input _Output NewCatalog* catalog) +SizeT NewFSParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog) { if (!catalog) { @@ -957,16 +972,16 @@ namespace Kernel::Detail sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); - Char partitionBlockBuf[sizeof(NewPartitionBlock)] = {0}; + Char partitionBlockBuf[sizeof(NFS_ROOT_PARTITION_BLOCK)] = {0}; sMountpointInterface.A().fPacket.fLba = kNewFSStartLba; sMountpointInterface.A().fPacket.fPacketContent = partitionBlockBuf; - sMountpointInterface.A().fPacket.fPacketSize = sizeof(NewPartitionBlock); + sMountpointInterface.A().fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); sMountpointInterface.A().fInput(&sMountpointInterface.A().fPacket); - NewPartitionBlock* partBlock = - reinterpret_cast<NewPartitionBlock*>(partitionBlockBuf); + NFS_ROOT_PARTITION_BLOCK* partBlock = + reinterpret_cast<NFS_ROOT_PARTITION_BLOCK*>(partitionBlockBuf); if (!StringBuilder::Equals(partBlock->Ident, kNewFSIdent)) { @@ -980,4 +995,4 @@ namespace Kernel::Detail } } // namespace Kernel::Detail -#endif // ifdef __FSKIT_NEWFS__ +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/Kernel/Sources/FS/compile_flags.txt b/Kernel/Sources/FS/compile_flags.txt new file mode 100644 index 00000000..39b236a9 --- /dev/null +++ b/Kernel/Sources/FS/compile_flags.txt @@ -0,0 +1,6 @@ +-nostdlib +-ffreestanding +-std=c++20 +-I./ +-I../ +-D__ED__ diff --git a/Kernel/Sources/FileManager.cxx b/Kernel/Sources/FileManager.cxx index 35913b85..dcdced27 100644 --- a/Kernel/Sources/FileManager.cxx +++ b/Kernel/Sources/FileManager.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -12,11 +12,11 @@ namespace Kernel { - static FilesystemManagerInterface* kMounted = nullptr; + STATIC FilesystemManagerInterface* kMounted = nullptr; /// @brief FilesystemManager getter. /// @return The mounted filesystem. - FilesystemManagerInterface* FilesystemManagerInterface::GetMounted() + _Output FilesystemManagerInterface* FilesystemManagerInterface::GetMounted() { return kMounted; } @@ -50,12 +50,12 @@ namespace Kernel return false; } -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ /// @brief Opens a new file. /// @param path /// @param r /// @return - NodePtr NewFilesystemManager::Open(_Input const Char* path, _Input const Char* r) + _Output NodePtr NewFilesystemManager::Open(_Input const Char* path, _Input const Char* r) { if (!path || *path == 0) return nullptr; @@ -81,8 +81,10 @@ namespace Kernel /// @return Void NewFilesystemManager::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) { - if (!node) return; - if (!size) return; + if (!node) + return; + if (!size) + return; constexpr auto cDataForkName = kNewFSDataFork; this->Write(cDataForkName, node, data, flags, size); @@ -93,10 +95,12 @@ namespace Kernel /// @param flags the flags with it. /// @param sz the size to read. /// @return - VoidPtr NewFilesystemManager::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) + _Output VoidPtr NewFilesystemManager::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) { - if (!node) return nullptr; - if (!size) return nullptr; + if (!node) + return nullptr; + if (!size) + return nullptr; constexpr auto cDataForkName = kNewFSDataFork; return this->Read(cDataForkName, node, flags, size); @@ -117,8 +121,8 @@ namespace Kernel NEWOS_UNUSED(flags); - if ((reinterpret_cast<NewCatalog*>(node))->Kind == kNewFSCatalogKindFile) - fImpl->WriteCatalog(reinterpret_cast<NewCatalog*>(node), data, size, + if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNewFSCatalogKindFile) + fImpl->WriteCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), data, size, name); } @@ -135,8 +139,8 @@ namespace Kernel NEWOS_UNUSED(flags); - if ((reinterpret_cast<NewCatalog*>(node))->Kind == kNewFSCatalogKindFile) - return fImpl->ReadCatalog(reinterpret_cast<NewCatalog*>(node), sz, + if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNewFSCatalogKindFile) + return fImpl->ReadCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), sz, name); return nullptr; @@ -148,12 +152,12 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - bool NewFilesystemManager::Seek(NodePtr node, SizeT off) + _Output Bool NewFilesystemManager::Seek(NodePtr node, SizeT off) { if (!node || off == 0) return false; - return fImpl->Seek(reinterpret_cast<NewCatalog*>(node), off); + return fImpl->Seek(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), off); } /// @brief Tell where the catalog is. @@ -161,12 +165,12 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - SizeT NewFilesystemManager::Tell(NodePtr node) + _Output SizeT NewFilesystemManager::Tell(NodePtr node) { if (!node) return kNPos; - return fImpl->Tell(reinterpret_cast<NewCatalog*>(node)); + return fImpl->Tell(reinterpret_cast<NFS_CATALOG_STRUCT*>(node)); } /// @brief Rewinds the catalog. @@ -174,7 +178,7 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - bool NewFilesystemManager::Rewind(NodePtr node) + _Output Bool NewFilesystemManager::Rewind(NodePtr node) { if (!node) return false; @@ -184,9 +188,9 @@ namespace Kernel /// @brief Returns the filesystem parser. /// @return the Filesystem parser class. - NewFSParser* NewFilesystemManager::GetParser() noexcept + _Output NewFSParser* NewFilesystemManager::GetParser() noexcept { return fImpl; } -#endif // __FSKIT_NEWFS__ +#endif // __FSKIT_USE_NEWFS__ } // namespace Kernel diff --git a/Kernel/Sources/Framebuffer.cxx b/Kernel/Sources/Framebuffer.cxx index 205291bb..f006a9b9 100644 --- a/Kernel/Sources/Framebuffer.cxx +++ b/Kernel/Sources/Framebuffer.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: Framebuffer.cxx Purpose: Framebuffer object @@ -9,88 +9,105 @@ 01/02/24: Added file (amlel) 02/02/24: Add documentation (amlel) + 07/07/07: Moved Framebuffer methods into Kernel:: ------------------------------------------- */ #include <KernelKit/Framebuffer.hpp> +#include <HintKit/CompilerHint.hxx> /** * @brief Framebuffer object implementation. * */ -using namespace Kernel; - namespace Kernel { - const UInt32 kRgbRed = 0x000000FF; - const UInt32 kRgbGreen = 0x0000FF00; - const UInt32 kRgbBlue = 0x00FF0000; - const UInt32 kRgbBlack = 0x00000000; - const UInt32 kRgbWhite = 0xFFFFFFFF; -} // namespace Kernel + Framebuffer::Framebuffer(_Input Ref<FramebufferContext*>& addr) + : fFrameBufferAddr(addr) + { + } -/** - * @brief Get Pixel at - * - * @param pos position of pixel. - * @return volatile* - */ -volatile UIntPtr* Framebuffer::operator[](const UIntPtr& pos) -{ - return (UIntPtr*)(fFrameBufferAddr->fBase * pos); -} + /** + * @brief Get Pixel at **pos** + * + * @param pos position of pixel. + * @return volatile* + */ + _Output volatile UIntPtr* Framebuffer::operator[](_Input const UIntPtr& pos) + { + return (UIntPtr*)(fFrameBufferAddr->fBase * pos); + } -/// @brief Boolean operator. -Framebuffer::operator bool() -{ - return fFrameBufferAddr.Leak()->fBase != 0 && - fColour != FramebufferColorKind::INVALID && - fFrameBufferAddr.Leak()->fBase != kBadPtr; -} - -/// @brief Set color kind of framebuffer. -/// @param colour -/// @return -const FramebufferColorKind& Framebuffer::Color( - const FramebufferColorKind& colour) -{ - if (fColour != FramebufferColorKind::INVALID && - colour != FramebufferColorKind::INVALID) + /// @brief Boolean operator. + Framebuffer::operator bool() { - fColour = colour; + return fFrameBufferAddr.Leak()->fBase != 0 && + fColour != FramebufferColorKind::INVALID && + fFrameBufferAddr.Leak()->fBase != kBadPtr; } - return fColour; -} + /// @brief Set color kind of framebuffer. + /// @param colour + /// @return + _Output const FramebufferColorKind& Framebuffer::Color( + const FramebufferColorKind& colour) + { + if (fColour != FramebufferColorKind::INVALID && + colour != FramebufferColorKind::INVALID) + { + fColour = colour; + } + + return fColour; + } -/// @brief Leak framebuffer context. -/// @return The reference of the framebuffer context. -Ref<FramebufferContext*>& Framebuffer::Leak() -{ - return this->fFrameBufferAddr; -} + /// @brief Leak framebuffer context. + /// @return The reference of the framebuffer context. + _Output Ref<FramebufferContext*>& Framebuffer::Leak() + { + return this->fFrameBufferAddr; + } -Framebuffer& Framebuffer::DrawRect(SizeT width, SizeT height, SizeT x, SizeT y, UInt32 color) -{ - for (Kernel::SizeT i = x; i < width + x; ++i) + /// @brief Draws a rectangle. + /// @param width + /// @param height + /// @param x + /// @param y + /// @param color + /// @return + _Output Framebuffer& Framebuffer::DrawRect(SizeT width, SizeT height, SizeT x, SizeT y, UInt32 color) { - for (Kernel::SizeT u = y; u < height + y; ++u) + for (Kernel::SizeT i = x; i < width + x; ++i) { - *(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase + - 4 * fFrameBufferAddr.Leak()->fBpp * i + - 4 * u))) = color; + for (Kernel::SizeT u = y; u < height + y; ++u) + { + *(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase + + 4 * fFrameBufferAddr.Leak()->fBpp * i + + 4 * u))) = color; + } } + + return *this; } - return *this; -} + /// @brief Put a pixel on the screen. + /// @param x + /// @param y + /// @param color + /// @return + _Output Framebuffer& Framebuffer::PutPixel(SizeT x, SizeT y, UInt32 color) + { + *(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase + + 4 * fFrameBufferAddr.Leak()->fBpp * x + + 4 * y))) = color; -Framebuffer& Framebuffer::PutPixel(SizeT x, SizeT y, UInt32 color) -{ - *(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase + - 4 * fFrameBufferAddr.Leak()->fBpp * x + - 4 * y))) = color; + return *this; + } - return *this; -}
\ No newline at end of file + const UInt32 kRgbRed = 0x000000FF; + const UInt32 kRgbGreen = 0x0000FF00; + const UInt32 kRgbBlue = 0x00FF0000; + const UInt32 kRgbBlack = 0x00000000; + const UInt32 kRgbWhite = 0xFFFFFFFF; +} // namespace Kernel diff --git a/Kernel/Sources/GUIDWizard.cxx b/Kernel/Sources/GUIDWizard.cxx index 0af8e289..b65c73a8 100644 --- a/Kernel/Sources/GUIDWizard.cxx +++ b/Kernel/Sources/GUIDWizard.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: GUIDWizard.cxx Purpose: GUID helper code @@ -10,7 +10,7 @@ ------------------------------------------- */ #include <CFKit/GUIDWizard.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> // begin of ascii 'readable' characters. (A, C, C, 1, 2) #define kAsciiBegin 47 @@ -19,24 +19,31 @@ namespace Kernel::XRN::Version1 { - auto make_sequence(const ArrayList<UShort>& uuidSeq) -> Ref<GUIDSequence*> + auto cf_make_sequence(const ArrayList<UInt32>& uuidSeq) -> Ref<GUIDSequence*> { GUIDSequence* seq = new GUIDSequence(); MUST_PASS(seq); Ref<GUIDSequence*> sequenceReference{seq, true}; - sequenceReference->fMs1 |= uuidSeq[0]; - sequenceReference->fMs2 |= uuidSeq[1]; - sequenceReference->fMs3 |= uuidSeq[2]; - sequenceReference->fMs3 |= uuidSeq[3]; + sequenceReference->fMs1 = uuidSeq[0]; + sequenceReference->fMs2 = uuidSeq[1]; + sequenceReference->fMs3 = uuidSeq[2]; + sequenceReference->fMs4[0] = uuidSeq[3]; + sequenceReference->fMs4[1] = uuidSeq[4]; + sequenceReference->fMs4[2] = uuidSeq[5]; + sequenceReference->fMs4[3] = uuidSeq[6]; + sequenceReference->fMs4[4] = uuidSeq[7]; + sequenceReference->fMs4[5] = uuidSeq[8]; + sequenceReference->fMs4[6] = uuidSeq[9]; + sequenceReference->fMs4[7] = uuidSeq[10]; 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>> + auto cf_try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<StringView>> { Char buf[kUUIDSize]; diff --git a/Kernel/Sources/GUIDWrapper.cxx b/Kernel/Sources/GUIDWrapper.cxx index 259c76e2..c7b4fc7c 100644 --- a/Kernel/Sources/GUIDWrapper.cxx +++ b/Kernel/Sources/GUIDWrapper.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/HError.cxx b/Kernel/Sources/HError.cxx index 23d63953..f10c3a15 100644 --- a/Kernel/Sources/HError.cxx +++ b/Kernel/Sources/HError.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/HalPageAlloc.cxx b/Kernel/Sources/HalPageAlloc.cxx index 0339745b..75e31e86 100644 --- a/Kernel/Sources/HalPageAlloc.cxx +++ b/Kernel/Sources/HalPageAlloc.cxx @@ -1,15 +1,15 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <ArchKit/ArchKit.hpp> #ifdef __NEWOS_AMD64__ -#include <HALKit/AMD64/HalPageAlloc.hpp> +#include <HALKit/AMD64/HalPageAlloc.hxx> #elif defined(__NEWOS_ARM64__) -#include <HALKit/ARM64/HalPageAlloc.hpp> +#include <HALKit/ARM64/HalPageAlloc.hxx> #endif #include <NewKit/Defines.hpp> @@ -29,7 +29,7 @@ namespace Kernel Boolean Present; Boolean ReadWrite; Boolean User; - SizeT PageSize; + SizeT Size; }; struct VirtualMemoryHeaderTraits @@ -39,7 +39,7 @@ namespace Kernel /// @return VirtualMemoryHeader* Next(VirtualMemoryHeader* current) { - return current + sizeof(PTE) + current->PageSize; + return current + sizeof(VirtualMemoryHeader) + current->Size; } /// @brief Get previous header. @@ -47,7 +47,7 @@ namespace Kernel /// @return VirtualMemoryHeader* Prev(VirtualMemoryHeader* current) { - return current - sizeof(PTE) - current->PageSize; + return current - sizeof(VirtualMemoryHeader) - current->Size; } }; } // namespace Detail @@ -80,7 +80,7 @@ namespace Kernel vmHeader->Present = true; vmHeader->ReadWrite = rw; vmHeader->User = user; - vmHeader->PageSize = size; + vmHeader->Size = size; kAllocationInProgress = false; diff --git a/Kernel/Sources/KernelHeap.cxx b/Kernel/Sources/Heap.cxx index 7bfd9c07..6ac91448 100644 --- a/Kernel/Sources/KernelHeap.cxx +++ b/Kernel/Sources/Heap.cxx @@ -1,17 +1,17 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <KernelKit/DebugOutput.hpp> #include <KernelKit/HError.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <NewKit/Crc32.hpp> #include <NewKit/PageManager.hpp> //! @file KernelHeap.cxx -//! @brief Kernel allocator. +//! @brief Kernel heap allocator. #define kKernelHeapMagic (0xD4D7D5) #define kKernelHeapHeaderPaddingSz (16U) @@ -47,23 +47,47 @@ namespace Kernel typedef HeapInformationBlock* HeapInformationBlockPtr; } // namespace Detail + /// @brief Declare a new size for allocatedPtr. + /// @param allocatedPtr the pointer. + /// @return + voidPtr ke_realloc_ke_heap(voidPtr allocatedPtr, SizeT newSz) + { + if (!allocatedPtr || newSz < 1) + return nullptr; + + Detail::HeapInformationBlockPtr heapInfoBlk = + reinterpret_cast<Detail::HeapInformationBlockPtr>( + (UIntPtr)allocatedPtr - sizeof(Detail::HeapInformationBlock)); + + heapInfoBlk->fTargetPtrSize = newSz; + + if (heapInfoBlk->fCRC32 > 0) + { + MUST_PASS(ke_protect_ke_heap(allocatedPtr)); + } + + return allocatedPtr; + } + /// @brief allocate chunk of memory. /// @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 ke_new_ke_heap(SizeT sz, const bool rw, const bool user) + VoidPtr ke_new_ke_heap(const SizeT sz, const bool rw, const bool user) { - if (sz == 0) - ++sz; + auto szFix = sz; + + if (szFix == 0) + ++szFix; - auto wrapper = kHeapPageManager.Request(rw, user, false, sz); + auto wrapper = kHeapPageManager.Request(rw, user, false, szFix); Detail::HeapInformationBlockPtr heapInfo = reinterpret_cast<Detail::HeapInformationBlockPtr>( wrapper.VirtualAddress()); - heapInfo->fTargetPtrSize = sz; + heapInfo->fTargetPtrSize = szFix; heapInfo->fMagic = kKernelHeapMagic; heapInfo->fCRC32 = 0; // dont fill it for now. heapInfo->fTargetPtr = wrapper.VirtualAddress(); @@ -130,10 +154,10 @@ namespace Kernel } heapInfoBlk->fTargetPtrSize = 0UL; - heapInfoBlk->fPresent = false; - heapInfoBlk->fTargetPtr = 0; - heapInfoBlk->fCRC32 = 0; - heapInfoBlk->fMagic = 0; + heapInfoBlk->fPresent = false; + heapInfoBlk->fTargetPtr = 0; + heapInfoBlk->fCRC32 = 0; + heapInfoBlk->fMagic = 0; PTEWrapper pageWrapper(false, false, false, reinterpret_cast<UIntPtr>(heapInfoBlk)); Ref<PTEWrapper*> pteAddress{&pageWrapper}; diff --git a/Kernel/Sources/IndexableProperty.cxx b/Kernel/Sources/IndexableProperty.cxx index 5cb1d54a..940a7d7a 100644 --- a/Kernel/Sources/IndexableProperty.cxx +++ b/Kernel/Sources/IndexableProperty.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Json.cxx b/Kernel/Sources/Json.cxx index 16a74765..ffec19ce 100644 --- a/Kernel/Sources/Json.cxx +++ b/Kernel/Sources/Json.cxx @@ -1,12 +1,12 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <NewKit/Json.hpp> +#include <NewKit/Json.hxx> using namespace Kernel; /// @brief Undefined object, is null in length. -INIT(Kernel::JsonType::kUndefined, Kernel::JsonType); +cInitObject(Kernel::JsonType::kNull, Kernel::JsonType); diff --git a/Kernel/Sources/KernelCheck.cxx b/Kernel/Sources/KernelCheck.cxx index 6eb5429c..690c8e8f 100644 --- a/Kernel/Sources/KernelCheck.cxx +++ b/Kernel/Sources/KernelCheck.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -8,10 +8,12 @@ #include <KernelKit/DebugOutput.hpp> #include <NewKit/KernelCheck.hpp> #include <NewKit/String.hpp> +#include <FirmwareKit/Handover.hxx> +#include <Modules/ACPI/ACPIFactoryInterface.hxx> -EXTERN_C [[noreturn]] void ke_wait_for_debugger() +EXTERN_C [[noreturn]] Kernel::Void ke_wait_for_debugger() { - while (true) + while (Yes) { #ifdef __NEWOS_AMD64__ Kernel::HAL::rt_cli(); @@ -88,12 +90,20 @@ namespace Kernel } }; - DumpManager::Dump(); + RecoveryFactory::Recover(); + } + + Void RecoveryFactory::Recover() noexcept + { #ifdef __DEBUG__ ke_wait_for_debugger(); #endif // ifdef __DEBUG__ + + PowerFactoryInterface powerInterface(kHandoverHeader->f_HardwareTables.f_VendorPtr); + powerInterface.Shutdown(); } + void ke_runtime_check(bool expr, const char* file, const char* line) { @@ -105,7 +115,7 @@ namespace Kernel #endif // __DEBUG__ - Kernel::ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed + ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed } } } // namespace Kernel diff --git a/Kernel/Sources/LockDelegate.cxx b/Kernel/Sources/LockDelegate.cxx index 6f0aa1d4..df9eb3e4 100644 --- a/Kernel/Sources/LockDelegate.cxx +++ b/Kernel/Sources/LockDelegate.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/Main.cxx index 7ec96539..0f835adc 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/Main.cxx @@ -1,9 +1,9 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies - File: KeMain.cxx - Purpose: Kernel main loop. + File: Main.cxx + Purpose: Main entrypoint of kernel. ------------------------------------------- */ @@ -13,20 +13,24 @@ #include <FirmwareKit/Handover.hxx> #include <KernelKit/FileManager.hpp> #include <KernelKit/Framebuffer.hpp> -#include <KernelKit/KernelHeap.hpp> -#include <KernelKit/PEF.hpp> +#include <KernelKit/Heap.hxx> +#include <KernelKit/PEF.hxx> #include <KernelKit/PEFCodeManager.hxx> #include <KernelKit/ProcessScheduler.hxx> -#include <KernelKit/UserHeap.hpp> -#include <NewKit/Json.hpp> +#include <KernelKit/ProcessHeap.hxx> +#include <NewKit/Json.hxx> #include <NewKit/KernelCheck.hpp> #include <NewKit/String.hpp> #include <NewKit/Utils.hpp> #include <KernelKit/CodeManager.hpp> +#include <CFKit/Property.hpp> + +EXTERN Kernel::Property cKernelVersion; +EXTERN Kernel::Property cAutoFormatDisk; namespace Kernel::Detail { - /// @brief Filesystem auto installer, additional checks are also done by the class. + /// @brief Filesystem auto formatter, additional checks are also done by the class. class FilesystemInstaller final { Kernel::NewFilesystemManager* fNewFS{nullptr}; @@ -35,16 +39,20 @@ namespace Kernel::Detail /// @brief wizard constructor. explicit FilesystemInstaller() { + if (cAutoFormatDisk.GetValue() == No) + { + return; + } + if (Kernel::FilesystemManagerInterface::GetMounted()) { - /// Mounted partition, cool! + // Partition is mounted, cool! Kernel::kcout - << "newoskrnl: No need to create for a NewFS partition here...\r"; + << "newoskrnl: No need to create for a new NewFS (EPM) partition here...\r"; } else { - /// Not mounted partition, auto-mount. - ///! Mounts a NewFS block. + // Mounts a NewFS from main drive. fNewFS = new Kernel::NewFilesystemManager(); Kernel::FilesystemManagerInterface::Mount(fNewFS); @@ -54,8 +62,8 @@ namespace Kernel::Detail constexpr auto cFolderInfo = "META-INF"; const auto cDirCount = 9; const char* cDirStr[cDirCount] = { - "C:\\Boot\\", "C:\\System\\", "C:\\Support\\", "C:\\Applications\\", - "C:\\Users\\", "C:\\Library\\", "C:\\Mount\\", "C:\\DCIM\\", "C:\\Storage\\"}; + "\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\", + "\\Users\\", "\\Library\\", "\\Mounted\\", "\\DCIM\\", "\\Applications\\Store\\"}; for (Kernel::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) { @@ -63,7 +71,7 @@ namespace Kernel::Detail if (catalogDir) { - Kernel::kcout << "newoskrnl: Already here\r"; + Kernel::kcout << "newoskrnl: already exists.\r"; delete catalogDir; continue; @@ -72,16 +80,16 @@ namespace Kernel::Detail catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, kNewFSCatalogKindDir); - NewFork theFork{0}; + NFS_FORK_STRUCT theFork{0}; const Kernel::Char* cSrcName = cFolderInfo; Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theFork.ForkName, - Kernel::rt_string_len(cSrcName)); + Kernel::rt_string_len(cSrcName)); Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDir->Name), - theFork.CatalogName, - Kernel::rt_string_len(catalogDir->Name)); + theFork.CatalogName, + Kernel::rt_string_len(catalogDir->Name)); delete catalogDir; @@ -93,7 +101,7 @@ namespace Kernel::Detail Kernel::StringView metadataFolder(kNewFSSectorSz); metadataFolder += - "<p>Kind: folder</p>\r<p>Created by: system</p>\r<p>Edited by: " + "<!properties/>\r<p>Kind: folder</p>\r<p>Created by: system</p>\r<p>Edited by: " "system</p>\r<p>Volume Type: Zeta</p>\r"; metadataFolder += "<p>Path: "; @@ -114,28 +122,24 @@ namespace Kernel::Detail } } - NewCatalog* catalogDisk = - this->fNewFS->GetParser()->GetCatalog("C:\\Mount\\SIM:"); + NFS_CATALOG_STRUCT* catalogDisk = + this->fNewFS->GetParser()->GetCatalog("\\Mount\\SIM:"); const Kernel::Char* cSrcName = "DISK-INF"; if (catalogDisk) { - auto bufferInfoDisk = (Kernel::Char*)this->fNewFS->GetParser()->ReadCatalog(catalogDisk, kNewFSSectorSz, cSrcName); - Kernel::kcout << bufferInfoDisk << Kernel::end_line(); - - delete bufferInfoDisk; delete catalogDisk; } else { catalogDisk = - (NewCatalog*)this->Leak()->CreateAlias("C:\\Mount\\SIM:"); + (NFS_CATALOG_STRUCT*)this->Leak()->CreateAlias("\\Mount\\SIM:"); Kernel::StringView diskFolder(kNewFSSectorSz); diskFolder += - "<p>Kind: alias to SIM Card</p>\r<p>Created by: system</p>\r<p>Edited " + "<!properties/><p>Kind: alias to SIM Card</p>\r<p>Created by: system</p>\r<p>Edited " "by: " "system</p>\r<p>Volume Type: SIM Card</p>\r"; @@ -143,14 +147,14 @@ namespace Kernel::Detail diskFolder += Kernel::NewFilesystemHelper::Root(); diskFolder += "</p>\r"; - NewFork theDiskFork{0}; + NFS_FORK_STRUCT theDiskFork{0}; Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theDiskFork.ForkName, - Kernel::rt_string_len(cSrcName)); + Kernel::rt_string_len(cSrcName)); Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDisk->Name), - theDiskFork.CatalogName, - Kernel::rt_string_len(catalogDisk->Name)); + theDiskFork.CatalogName, + Kernel::rt_string_len(catalogDisk->Name)); theDiskFork.DataSize = kNewFSForkSize; theDiskFork.ResourceId = 0; @@ -162,8 +166,6 @@ namespace Kernel::Detail (Kernel::VoidPtr)diskFolder.CData(), kNewFSSectorSz, cSrcName); - Kernel::kcout << diskFolder.CData() << Kernel::end_line(); - delete catalogDisk; } } @@ -184,29 +186,15 @@ namespace Kernel::Detail /// @brief Loads necessary servers for the kernel -> user mode switch. /// @param void no args. /// @return void no return value. - STATIC Kernel::Void ke_launch_srv(Kernel::Void) + STATIC Kernel::Void ke_user_switch(Kernel::Void) { - // load security server. - Kernel::PEFLoader launchDevil("C:\\System\\launchd"); - if (!launchDevil.IsLoaded()) - { - Kernel::ke_stop(RUNTIME_CHECK_FAILED); - } - - Kernel::Utils::execute_from_image(launchDevil, - Kernel::ProcessHeader::kAppKind); + Kernel::UserView::The()->fRootUser = new User(RingKind::kRingSuperUser, kSuperUser); + Kernel::kcout << "newoskrnl: logged in as: " << Kernel::UserView::The()->fRootUser->Name().CData() << Kernel::endl; - /// load middleware service. - Kernel::PEFLoader stageBoard("C:\\System\\stageboard"); - - if (!stageBoard.IsLoaded()) - { - Kernel::ke_stop(RUNTIME_CHECK_FAILED); - } + Kernel::UserView::The()->LogIn(Kernel::UserView::The()->fRootUser); - Kernel::Utils::execute_from_image(stageBoard, - Kernel::ProcessHeader::kAppKind); + Kernel::kcout << "newoskrnl: " << cKernelVersion.GetKey().CData() << ": " << Kernel::number(cKernelVersion.GetValue()) << Kernel::endl; } } // namespace Kernel::Detail @@ -217,5 +205,5 @@ EXTERN_C Kernel::Void KeMain(Kernel::Void) { /// Now run kernel loop, until no process are running. Kernel::Detail::FilesystemInstaller(); // automatic filesystem creation. - Kernel::Detail::ke_launch_srv(); + Kernel::Detail::ke_user_switch(); } diff --git a/Kernel/Sources/MutableArray.cxx b/Kernel/Sources/MutableArray.cxx index 2099c01a..2bc62fcb 100644 --- a/Kernel/Sources/MutableArray.cxx +++ b/Kernel/Sources/MutableArray.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Network/IP.cxx b/Kernel/Sources/Network/IP.cxx index 676e12a8..64da3448 100644 --- a/Kernel/Sources/Network/IP.cxx +++ b/Kernel/Sources/Network/IP.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -90,13 +90,13 @@ namespace Kernel return true; } - ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress6> ipv6) + ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress6>& ipv6) { auto str = StringBuilder::Construct(ipv6.Leak().Address()); return str; } - ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress> ipv4) + ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress>& ipv4) { auto str = StringBuilder::Construct(ipv4.Leak().Address()); return str; diff --git a/Kernel/Sources/Network/IPCEP.cxx b/Kernel/Sources/Network/IPCEP.cxx index 1869035b..54d94b18 100644 --- a/Kernel/Sources/Network/IPCEP.cxx +++ b/Kernel/Sources/Network/IPCEP.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -12,46 +12,39 @@ using namespace Kernel; /// @internal /// @brief The internal sanitize function. -Bool __ipc_sanitize_packet(IPCEPMessageHeader* pckt) +Bool ipc_int_sanitize_packet(IPCEPMessageHeader* pckt) { - if (!pckt) return false; - auto endian = DEDUCE_ENDIAN(pckt, ((char*)pckt)[0]); switch (endian) { - case Endian::kEndianBig: - { + case Endian::kEndianBig: { if (pckt->IpcEndianess == eIPCEPLittleEndian) - goto _Fail; + goto ipc_check_failed; break; } - case Endian::kEndianLittle: - { + case Endian::kEndianLittle: { if (pckt->IpcEndianess == eIPCEPBigEndian) - goto _Fail; + goto ipc_check_failed; break; } case Endian::kEndianMixed: break; default: - goto _Fail; + goto ipc_check_failed; } - if (pckt->IpcFrom == pckt->IpcTo) + if (pckt->IpcFrom == pckt->IpcTo || + pckt->IpcPacketSize > cIPCEPMsgSize) { - goto _Fail; - } - if (pckt->IpcPacketSize > cIPCEPMsgSize) - { - goto _Fail; + goto ipc_check_failed; } return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cRemoteHeaderMagic; -_Fail: +ipc_check_failed: ErrLocal() = kErrorIPC; return false; } @@ -63,7 +56,8 @@ namespace Kernel /// @retval false packet is incorrect and process has crashed. Bool ipc_sanitize_packet(IPCEPMessageHeader* pckt) { - if (!__ipc_sanitize_packet(pckt)) + if (!pckt || + !ipc_int_sanitize_packet(pckt)) { ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return false; @@ -71,4 +65,4 @@ namespace Kernel return true; } -} +} // namespace Kernel diff --git a/Kernel/Sources/Network/NetworkDevice.cxx b/Kernel/Sources/Network/NetworkDevice.cxx index 4ee633e8..7c61460e 100644 --- a/Kernel/Sources/Network/NetworkDevice.cxx +++ b/Kernel/Sources/Network/NetworkDevice.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/New+Delete.cxx b/Kernel/Sources/New+Delete.cxx index d87df3e6..2921e079 100644 --- a/Kernel/Sources/New+Delete.cxx +++ b/Kernel/Sources/New+Delete.cxx @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <NewKit/New.hpp> void* operator new[](size_t sz) diff --git a/Kernel/Sources/NewFS+FileManager.cxx b/Kernel/Sources/NewFS+FileManager.cxx index 2658d784..146f721d 100644 --- a/Kernel/Sources/NewFS+FileManager.cxx +++ b/Kernel/Sources/NewFS+FileManager.cxx @@ -1,13 +1,13 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <KernelKit/FileManager.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ /// @brief NewFS File manager. /// BUGS: 0 @@ -86,4 +86,4 @@ namespace Kernel } } // namespace Kernel -#endif // ifdef __FSKIT_NEWFS__ +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/Kernel/Sources/NewFS+IO.cxx b/Kernel/Sources/NewFS+IO.cxx index 884f8c11..314d309a 100644 --- a/Kernel/Sources/NewFS+IO.cxx +++ b/Kernel/Sources/NewFS+IO.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -13,11 +13,11 @@ * Purpose: Filesystem to mountpoint interface. * Date: 3/26/24 * - * Copyright Zeta Electronics Corporation, all rights reserved. + * Copyright ZKA Technologies, all rights reserved. * *************************************************************/ -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ #include <FirmwareKit/EPM.hxx> @@ -98,4 +98,4 @@ Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIn return DrvTrait.fPacket.fPacketGood; } -#endif // ifdef __FSKIT_NEWFS__ +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/Kernel/Sources/NewFS+Journal.cxx b/Kernel/Sources/NewFS+Journal.cxx index f69744cc..8685f6ee 100644 --- a/Kernel/Sources/NewFS+Journal.cxx +++ b/Kernel/Sources/NewFS+Journal.cxx @@ -1,13 +1,13 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <KernelKit/DebugOutput.hpp> #include <KernelKit/FileManager.hpp> -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ ///! BUGS: 0 ///! @file NewFS+Journal.cxx @@ -19,4 +19,4 @@ namespace Kernel::Journal using namespace Kernel; -#endif // ifdef __FSKIT_NEWFS__ +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/Kernel/Sources/OwnPtr.cxx b/Kernel/Sources/OwnPtr.cxx index ca129740..cfb51b86 100644 --- a/Kernel/Sources/OwnPtr.cxx +++ b/Kernel/Sources/OwnPtr.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/PEFCodeManager.cxx b/Kernel/Sources/PEFCodeManager.cxx index 6f06ac37..8b1918ef 100644 --- a/Kernel/Sources/PEFCodeManager.cxx +++ b/Kernel/Sources/PEFCodeManager.cxx @@ -1,11 +1,11 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <KernelKit/DebugOutput.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <KernelKit/PEFCodeManager.hxx> #include <KernelKit/ProcessScheduler.hxx> #include <NewKit/Defines.hpp> diff --git a/Kernel/Sources/PEFSharedObject.cxx b/Kernel/Sources/PEFSharedObject.cxx index 3e7ec9eb..dccb9d12 100644 --- a/Kernel/Sources/PEFSharedObject.cxx +++ b/Kernel/Sources/PEFSharedObject.cxx @@ -2,13 +2,13 @@ * ======================================================== * * Kernel - * Copyright Zeta Electronics Corporation, all rights reserved. + * Copyright ZKA Technologies, all rights reserved. * * ======================================================== */ #include <KernelKit/DebugOutput.hpp> -#include <KernelKit/PEF.hpp> +#include <KernelKit/PEF.hxx> #include <KernelKit/PEFSharedObject.hxx> #include <KernelKit/ProcessScheduler.hxx> #include <KernelKit/ThreadLocalStorage.hxx> @@ -18,66 +18,69 @@ Revision History: - 01/02/24: Rework shared library ABI, except a rt_library_init and - rt_library_free (amlel) 15/02/24: Breaking changes, changed the name of the + 01/02/24: Rework shared sharedObj ABI, except a rt_library_init and + rt_library_fini (amlel) 15/02/24: Breaking changes, changed the name of the routines. (amlel) + 07/28/24: Replace rt_library_free with rt_library_fini + ------------------------------------------- */ using namespace Kernel; /***********************************************************************************/ -/// @file SharedObjectRT.cxx -/// @brief Shared Object runtime. +/// @file PEFSharedObjectRT.cxx +/// @brief PEF's shared object runtime. /***********************************************************************************/ /***********************************************************************************/ -/* @brief Library runtime initializer. */ +/** @brief Library initializer. */ /***********************************************************************************/ EXTERN_C SharedObjectPtr rt_library_init(void) { - SharedObjectPtr library = tls_new_class<SharedObject>(); + SharedObjectPtr sharedObj = tls_new_class<SharedObject>(); - if (!library) + if (!sharedObj) { ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return nullptr; } - library->Mount(tls_new_class<SharedObject::SharedObjectTrait>()); + sharedObj->Mount(tls_new_class<SharedObject::SharedObjectTrait>()); - if (!library->Get()) + if (!sharedObj->Get()) { ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return nullptr; } - library->Get()->fImageObject = + sharedObj->Get()->fImageObject = ProcessScheduler::The().Leak().TheCurrent().Leak().Image; - if (!library->Get()->fImageObject) + if (!sharedObj->Get()->fImageObject) { ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return nullptr; } - library->Get()->fImageEntrypointOffset = - library->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart, 0), kPefCode); + sharedObj->Get()->fImageEntrypointOffset = + sharedObj->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart, 0), kPefCode); - return library; + return sharedObj; } /***********************************************************************************/ -/* @brief Ends the library. */ -/* @note Please check if the lib got freed! */ -/* @param SharedObjectPtr the library to free. */ +/** @brief Frees the sharedObj. */ +/** @note Please check if the lib got freed! */ +/** @param lib The sharedObj to free. */ +/** @param successful Reports if successful or not. */ /***********************************************************************************/ -EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool* successful) +EXTERN_C Void rt_library_fini(SharedObjectPtr lib, bool* successful) { MUST_PASS(successful); @@ -97,9 +100,10 @@ EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool* successful) } /***********************************************************************************/ - /// @brief Unimplemented function (crashes by default) /// @param +/***********************************************************************************/ + EXTERN_C void __mh_purecall(void) { kcout << "newoskrnl: unimplemented symbol!\r"; diff --git a/Kernel/Sources/PRDT.cxx b/Kernel/Sources/PRDT.cxx index 73dadbab..372df03f 100644 --- a/Kernel/Sources/PRDT.cxx +++ b/Kernel/Sources/PRDT.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/PageAllocator.cxx b/Kernel/Sources/PageAllocator.cxx index 27006885..5adf1de3 100644 --- a/Kernel/Sources/PageAllocator.cxx +++ b/Kernel/Sources/PageAllocator.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -26,11 +26,14 @@ namespace Kernel::Detail void exec_disable(UIntPtr VirtualAddr) { +#ifdef __NEWOS_SUPPORT_NX__ PTE* VirtualAddrTable = reinterpret_cast<PTE*>(VirtualAddr); - MUST_PASS(!VirtualAddrTable->Accessed); + + MUST_PASS(!VirtualAddrTable->ExecDisable == false); VirtualAddrTable->ExecDisable = true; hal_flush_tlb(); +#endif // ifdef __NEWOS_SUPPORT_NX__ } bool page_disable(UIntPtr VirtualAddr) @@ -38,8 +41,8 @@ namespace Kernel::Detail if (VirtualAddr) { auto VirtualAddrTable = (PTE*)(VirtualAddr); - MUST_PASS(!VirtualAddrTable->Accessed); + MUST_PASS(!VirtualAddrTable->Present == true); VirtualAddrTable->Present = false; hal_flush_tlb(); diff --git a/Kernel/Sources/PageManager.cxx b/Kernel/Sources/PageManager.cxx index 35693310..a9672b3b 100644 --- a/Kernel/Sources/PageManager.cxx +++ b/Kernel/Sources/PageManager.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -8,9 +8,9 @@ #include <NewKit/PageManager.hpp> #ifdef __NEWOS_AMD64__ -#include <HALKit/AMD64/HalPageAlloc.hpp> +#include <HALKit/AMD64/HalPageAlloc.hxx> #elif defined(__NEWOS_ARM64__) -#include <HALKit/ARM64/HalPageAlloc.hpp> +#include <HALKit/ARM64/HalPageAlloc.hxx> #endif // ifdef __NEWOS_AMD64__ || defined(__NEWOS_ARM64__) //! null deref will throw (Page Zero detected, aborting app!) diff --git a/Kernel/Sources/PermissionSelector.cxx b/Kernel/Sources/PermissionSelector.cxx deleted file mode 100644 index e5cfd409..00000000 --- a/Kernel/Sources/PermissionSelector.cxx +++ /dev/null @@ -1,47 +0,0 @@ -/* - * ======================================================== - * - * Kernel - * Copyright Zeta Electronics Corporation, all rights reserved. - * - * File: PermissionSelector.cpp - * Purpose: Permission selectors. - * - * ======================================================== - */ - -#include <KernelKit/PermissionSelector.hxx> -#include <NewKit/KernelCheck.hpp> - -/// bugs 0 - -namespace Kernel -{ - PermissionSelector::PermissionSelector(const Int32& sel) - : fRing((RingKind)sel) - { - MUST_PASS(sel > 0); - } - - 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; - } - - const RingKind& PermissionSelector::Ring() noexcept - { - return this->fRing; - } -} // namespace Kernel diff --git a/Kernel/Sources/Pmm.cxx b/Kernel/Sources/Pmm.cxx index 22813206..f3425c5a 100644 --- a/Kernel/Sources/Pmm.cxx +++ b/Kernel/Sources/Pmm.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -12,7 +12,7 @@ #endif #if defined(__NEWOS_AMD64__) -#include <HALKit/AMD64/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> #endif namespace Kernel diff --git a/Kernel/Sources/UserHeap.cxx b/Kernel/Sources/ProcessHeap.cxx index 453d1f30..86ac1554 100644 --- a/Kernel/Sources/UserHeap.cxx +++ b/Kernel/Sources/ProcessHeap.cxx @@ -1,16 +1,16 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <KernelKit/ProcessScheduler.hxx> -#include <KernelKit/UserHeap.hpp> +#include <KernelKit/ProcessHeap.hxx> #include <NewKit/PageManager.hpp> #define kHeapHeaderPaddingSz (16U) -/// @file UserHeap.cxx +/// @file ProcessHeap.cxx /// @brief User Heap Manager, Process heap allocator. /// @note if you want to look at the kernel allocator, please look for /// KernelHeap.cxx @@ -22,7 +22,7 @@ namespace Kernel * @brief Process Heap Header * @note Allocated per process, it denotes the user's heap. */ - struct UserHeapHeader final + struct PROCESS_HEAP_HEADER final { UInt32 fMagic; Int32 fFlags; @@ -30,35 +30,38 @@ namespace Kernel UInt8 fPadding[kHeapHeaderPaddingSz]; }; + /// @brief PROCESS_HEAP_HEADER as pointer type. + typedef PROCESS_HEAP_HEADER* PROCESS_HEAP_HEADER_PTR; + /** - * @brief User Heap Manager class, takes care of allocating the process pools. + * @brief Process heap class, takes care of allocating the process pools. * @note This rely on Virtual Memory! Consider adding good vmem support when * @note porting to a new arch. */ - class UserHeapManager final + class ProcessHeapHelper final { - UserHeapManager() = delete; + ProcessHeapHelper() = delete; public: - ~UserHeapManager() = default; + ~ProcessHeapHelper() = default; public: - STATIC SizeT& Count() + STATIC SizeT& Count() noexcept { return s_NumPools; } - STATIC Ref<Pmm>& Leak() + STATIC Ref<Pmm>& Leak() noexcept { return s_Pmm; } - STATIC Boolean& IsEnabled() + STATIC Boolean& IsEnabled() noexcept { return s_PoolsAreEnabled; } - STATIC MutableArray<Ref<PTEWrapper>>& The() + STATIC MutableArray<Ref<PTEWrapper>>& The() noexcept { return s_Pool; } @@ -74,10 +77,10 @@ namespace Kernel //! declare fields - SizeT UserHeapManager::s_NumPools = 0UL; - Ref<Pmm> UserHeapManager::s_Pmm; - Boolean UserHeapManager::s_PoolsAreEnabled = true; - MutableArray<Ref<PTEWrapper>> UserHeapManager::s_Pool; + SizeT ProcessHeapHelper::s_NumPools = 0UL; + Ref<Pmm> ProcessHeapHelper::s_Pmm; + Boolean ProcessHeapHelper::s_PoolsAreEnabled = true; + MutableArray<Ref<PTEWrapper>> ProcessHeapHelper::s_Pool; STATIC VoidPtr ke_find_unused_heap(Int32 flags); STATIC Void ke_free_heap_internal(VoidPtr vaddr); @@ -91,15 +94,15 @@ namespace Kernel { for (SizeT index = 0; index < kUserHeapMaxSz; ++index) { - if (UserHeapManager::The()[index] && - !UserHeapManager::The()[index].Leak().Leak().Present()) + if (ProcessHeapHelper::The()[index] && + !ProcessHeapHelper::The()[index].Leak().Leak().Present()) { - UserHeapManager::Leak().Leak().TogglePresent( - UserHeapManager::The()[index].Leak().Leak(), true); + ProcessHeapHelper::Leak().Leak().TogglePresent( + ProcessHeapHelper::The()[index].Leak().Leak(), true); kcout << "[ke_find_unused_heap] Done, trying to make a pool now...\r"; return ke_make_heap_internal( - (VoidPtr)UserHeapManager::The()[index].Leak().Leak().VirtualAddress(), + (VoidPtr)ProcessHeapHelper::The()[index].Leak().Leak().VirtualAddress(), flags); } } @@ -115,7 +118,7 @@ namespace Kernel { if (virtualAddress) { - UserHeapHeader* poolHdr = reinterpret_cast<UserHeapHeader*>(virtualAddress); + PROCESS_HEAP_HEADER* poolHdr = reinterpret_cast<PROCESS_HEAP_HEADER*>(virtualAddress); if (!poolHdr->fFree) { @@ -130,7 +133,7 @@ namespace Kernel kcout << "[ke_make_heap_internal] New allocation has been done.\n"; return reinterpret_cast<VoidPtr>( - (reinterpret_cast<UIntPtr>(virtualAddress) + sizeof(UserHeapHeader))); + (reinterpret_cast<UIntPtr>(virtualAddress) + sizeof(PROCESS_HEAP_HEADER))); } kcout << "[ke_make_heap_internal] Address is invalid"; @@ -143,8 +146,8 @@ namespace Kernel /// @return STATIC Void ke_free_heap_internal(VoidPtr virtualAddress) { - UserHeapHeader* poolHdr = reinterpret_cast<UserHeapHeader*>( - reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(UserHeapHeader)); + PROCESS_HEAP_HEADER* poolHdr = reinterpret_cast<PROCESS_HEAP_HEADER*>( + reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(PROCESS_HEAP_HEADER)); if (poolHdr->fMagic == kUserHeapMag) { @@ -170,18 +173,18 @@ namespace Kernel */ STATIC Boolean ke_check_and_free_heap(const SizeT& index, VoidPtr ptr) { - if (UserHeapManager::The()[index]) + if (ProcessHeapHelper::The()[index]) { // ErrorOr<>::operator Boolean /// if (address matches) /// -> Free heap. - if (UserHeapManager::The()[index].Leak().Leak().VirtualAddress() == + if (ProcessHeapHelper::The()[index].Leak().Leak().VirtualAddress() == (UIntPtr)ptr) { - UserHeapManager::Leak().Leak().FreePage( - UserHeapManager::The()[index].Leak().Leak()); + ProcessHeapHelper::Leak().Leak().FreePage( + ProcessHeapHelper::The()[index].Leak().Leak()); - --UserHeapManager::Count(); + --ProcessHeapHelper::Count(); ke_free_heap_internal(ptr); ptr = nullptr; @@ -198,24 +201,24 @@ namespace Kernel /// @return a pool pointer with selected permissions. VoidPtr rt_new_heap(Int32 flags) { - if (!UserHeapManager::IsEnabled()) + if (!ProcessHeapHelper::IsEnabled()) return nullptr; - if (UserHeapManager::Count() > kUserHeapMaxSz) + if (ProcessHeapHelper::Count() > kUserHeapMaxSz) return nullptr; if (VoidPtr ret = ke_find_unused_heap(flags)) return ret; // this wasn't set to true - auto ref_page = UserHeapManager::Leak().Leak().RequestPage( + auto ref_page = ProcessHeapHelper::Leak().Leak().RequestPage( ((flags & kUserHeapUser)), (flags & kUserHeapRw)); if (ref_page) { ///! reserve page. - UserHeapManager::The()[UserHeapManager::Count()].Leak() = ref_page; - auto& ref = UserHeapManager::Count(); + ProcessHeapHelper::The()[ProcessHeapHelper::Count()].Leak() = ref_page; + auto& ref = ProcessHeapHelper::Count(); ++ref; // increment the number of addresses we have now. @@ -232,12 +235,12 @@ namespace Kernel /// @return status code Int32 rt_free_heap(VoidPtr ptr) { - if (!UserHeapManager::IsEnabled()) + if (!ProcessHeapHelper::IsEnabled()) return -1; if (ptr) { - SizeT base = UserHeapManager::Count(); + SizeT base = ProcessHeapHelper::Count(); if (ke_check_and_free_heap(base, ptr)) return 0; diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index 316a9362..bfa6fddf 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -11,7 +11,7 @@ #include <KernelKit/ProcessScheduler.hxx> #include <KernelKit/SMPManager.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <NewKit/String.hpp> #include <KernelKit/HError.hpp> @@ -29,14 +29,9 @@ namespace Kernel STATIC Int32 cLastExitCode = 0U; - /// @brief Gets the latest exit code. + /// @brief Gets the last exit code. /// @note Not thread-safe. /// @return Int32 the last exit code. - const Int32& ProcessHeader::GetExitCode() noexcept - { - return fLastExitCode; - } - const Int32& rt_get_exit_code() noexcept { return cLastExitCode; @@ -48,14 +43,31 @@ namespace Kernel void ProcessHeader::Crash() { - kcout << (*this->Name == 0 ? "Unknown" : this->Name) << ": crashed. (id = "; + kcout << (*this->Name == 0 ? "Kernel" : this->Name) << ": crashed. (id = "; kcout.Number(kErrorProcessFault); kcout << ")\r"; + if (Kernel::ProcessScheduler::The().Leak().CurrentTeam().AsArray().Count() < 1) + { + kcout << "*** BAD PROCESS ***\rTerminating as we are the only process...\r"; + ke_stop(RUNTIME_CHECK_PROCESS); + } + this->Exit(kErrorProcessFault); } - Int32& ProcessHeader::GetLocalCode() noexcept { return fLocalCode; } + /// @brief Gets the local last exit code. + /// @note Not thread-safe. + /// @return Int32 the last exit code. + const Int32& ProcessHeader::GetExitCode() noexcept + { + return this->fLastExitCode; + } + + Int32& ProcessHeader::GetLocalCode() noexcept + { + return fLocalCode; + } void ProcessHeader::Wake(const bool should_wakeup) { @@ -73,13 +85,13 @@ namespace Kernel { ErrLocal() = kErrorHeapOutOfMemory; - /* we're going out of memory */ + /* We're going out of memory! crash... */ this->Crash(); return nullptr; } - this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor + (sizeof(sz))); + this->HeapCursor = reinterpret_cast<VoidPtr>((UIntPtr)this->HeapCursor + (sizeof(sz))); VoidPtr ptr = this->HeapCursor; ++this->UsedMemory; @@ -94,21 +106,17 @@ namespace Kernel /***********************************************************************************/ /* @brief checks if runtime pointer is in region. */ - bool rt_is_in_pool(VoidPtr pool_ptr, VoidPtr pool, const SizeT& sz) + bool rt_is_in_pool(VoidPtr pool_ptr, VoidPtr pool, const SizeT& pool_ptr_cur_sz, const SizeT& pool_ptr_used_sz) { - UIntPtr* _pool_ptr = (UIntPtr*)pool_ptr; - UIntPtr* _pool = (UIntPtr*)pool; - - for (SizeT index = sz; _pool[sz] != kUserHeapMag; --index) - { - if (&_pool[index] > &_pool_ptr[sz]) - continue; + if (pool == nullptr || + pool_ptr == nullptr) + return false; - if (_pool[index] == _pool_ptr[index]) - return true; - } + UIntPtr* uint_pool_ptr = (UIntPtr*)pool_ptr; + UIntPtr* uint_pool = (UIntPtr*)pool; - return false; + return (UIntPtr)&uint_pool > (UIntPtr)&uint_pool_ptr && + pool_ptr_cur_sz > pool_ptr_used_sz; } /* @brief free pointer from usage. */ @@ -121,7 +129,7 @@ namespace Kernel if (this->UsedMemory < 1) return false; - if (rt_is_in_pool(ptr, this->HeapCursor, this->UsedMemory)) + if (rt_is_in_pool(ptr, this->HeapCursor, this->UsedMemory, this->FreeMemory)) { this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor - (sizeof(sz))); rt_zero_memory(ptr, sz); @@ -136,7 +144,7 @@ namespace Kernel } /// @brief process name getter. - const Char* ProcessHeader::GetName() noexcept + const Char* ProcessHeader::GetProcessName() noexcept { return this->Name; } @@ -166,7 +174,7 @@ namespace Kernel /** @brief Standard exit proc. */ - void ProcessHeader::Exit(Int32 exit_code) + void ProcessHeader::Exit(const Int32& exit_code) { if (this->ProcessId != ProcessScheduler::The().Leak().TheCurrent().Leak().ProcessId) @@ -178,6 +186,7 @@ namespace Kernel //! Delete image if not done already. if (this->Image) ke_delete_ke_heap(this->Image); + if (this->StackFrame) ke_delete_ke_heap((VoidPtr)this->StackFrame); @@ -203,15 +212,23 @@ namespace Kernel if (mTeam.AsArray().Count() > kSchedProcessLimitPerTeam) return -kErrorOutOfTeamSlot; - kcout << "ProcessScheduler::Add(Ref<ProcessHeader>& process)\r"; + kcout << "ProcessScheduler:: adding process to team...\r"; /// Create heap according to type of process. if (process.Leak().Kind == ProcessHeader::kAppKind) + { process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw); + } else if (process.Leak().Kind == ProcessHeader::kShLibKind) + { process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw | kUserHeapShared); + } else - process.Leak().HeapPtr = rt_new_heap(kUserHeapDriver | kUserHeapRw); + { + // something went wrong, do not continue, process kind is incorrect. + process.Leak().Crash(); + return -kErrorProcessFault; + } process.Leak().StackFrame = reinterpret_cast<HAL::StackFrame*>( ke_new_ke_heap(sizeof(HAL::StackFrame), true, false)); @@ -223,22 +240,28 @@ namespace Kernel process.Leak().ProcessId = (mTeam.AsArray().Count() - 1); process.Leak().HeapCursor = process.Leak().HeapPtr; - mTeam.AsArray().Add(process); + MUST_PASS(mTeam.AsArray().Add(process)); - return mTeam.AsArray().Count() - 1; + return (mTeam.AsArray().Count() - 1); } /// @brief Remove process from list. - /// @param process - /// @return - bool ProcessScheduler::Remove(SizeT process) + /// @param processSlot process slot inside team. + /// @retval true process was removed. + /// @retval false process doesn't exist in team. + Bool ProcessScheduler::Remove(SizeT processSlot) { - if (process > mTeam.AsArray().Count()) + // check if process is within range. + if (processSlot > mTeam.AsArray().Count()) return false; - kcout << "ProcessScheduler::Remove(SizeT process)\r"; + // also check if the process isn't a dummy one. + if (mTeam.AsArray()[processSlot].Leak().Leak().Image == nullptr) + return false; - return mTeam.AsArray().Remove(process); + kcout << "ProcessScheduler: removing process\r"; + + return mTeam.AsArray().Remove(processSlot); } /// @brief Run scheduler. @@ -257,21 +280,21 @@ namespace Kernel { auto unwrapped_process = *process.Leak(); - unwrapped_process.PTime = 0; - // set the current process. mTeam.AsRef() = unwrapped_process; // tell helper to find a core to schedule on. - ProcessHelper::Switch(mTeam.AsRef().Leak().StackFrame, - mTeam.AsRef().Leak().ProcessId); + ProcessHelper::Switch(unwrapped_process.StackFrame, + unwrapped_process.ProcessId); - kcout << unwrapped_process.Name << ": process switched.\r"; + unwrapped_process.PTime = static_cast<Int32>(unwrapped_process.Affinity); + + kcout << unwrapped_process.Name << ": has been switched to process core.\r"; } else { // otherwise increment the P-time. - ++mTeam.AsRef().Leak().PTime; + --mTeam.AsRef().Leak().PTime; } } @@ -285,12 +308,14 @@ namespace Kernel return mTeam; } + /// @internal + STATIC Ref<ProcessScheduler> cSchedulerRef; + /// @brief Shared instance of the process scheduler. /// @return - Ref<ProcessScheduler&> ProcessScheduler::The() + Ref<ProcessScheduler>& ProcessScheduler::The() { - static ProcessScheduler ref; - return {ref}; + return cSchedulerRef; } /// @brief Gets current running process. @@ -320,10 +345,10 @@ namespace Kernel if (process.Leak().GetStatus() == ProcessStatus::kStarting) { - if (process.Leak().PTime < static_cast<Int>(kSchedMinMicroTime)) + if (process.Leak().PTime <= 0) { process.Leak().Status = ProcessStatus::kRunning; - process.Leak().Affinity = AffinityKind::kHartStandard; + process.Leak().Affinity = AffinityKind::kStandard; return true; } @@ -331,7 +356,7 @@ namespace Kernel ++process.Leak().PTime; } - return process.Leak().PTime > static_cast<Int>(kSchedMinMicroTime); + return process.Leak().PTime > 0; } /** diff --git a/Kernel/Sources/ProcessTeam.cxx b/Kernel/Sources/ProcessTeam.cxx index b55ae855..7f3fbcf8 100644 --- a/Kernel/Sources/ProcessTeam.cxx +++ b/Kernel/Sources/ProcessTeam.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Property.cxx b/Kernel/Sources/Property.cxx index db1e0579..60bd03da 100644 --- a/Kernel/Sources/Property.cxx +++ b/Kernel/Sources/Property.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -8,20 +8,19 @@ namespace Kernel { - Property::Property(const StringView& sw) - : fName(sw) - { - kcout << "Property: created: " << sw.CData() << endl; - } - Property::~Property() = default; bool Property::StringEquals(StringView& name) { - return fName && this->fName == name; + return this->fName && this->fName == name; + } + + StringView& Property::GetKey() + { + return this->fName; } - const PropertyId& Property::GetPropertyById() + PropertyId& Property::GetValue() { return fAction; } diff --git a/Kernel/Sources/Ref.cxx b/Kernel/Sources/Ref.cxx index 7661104e..b92ceac4 100644 --- a/Kernel/Sources/Ref.cxx +++ b/Kernel/Sources/Ref.cxx @@ -1,7 +1,7 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index 8b0aca9b..f5424525 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -1,12 +1,13 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <ArchKit/ArchKit.hpp> #include <KernelKit/ProcessScheduler.hxx> #include <KernelKit/SMPManager.hpp> +#include <CFKit/Property.hpp> ///! BUGS: 0 @@ -16,6 +17,8 @@ namespace Kernel { + STATIC Property cSMPCoreName; + ///! A HardwareThread class takes care of it's owned hardware thread. ///! It has a stack for it's core. @@ -120,7 +123,16 @@ namespace Kernel //! @brief Constructor and destructor ///! @brief Default constructor. - SMPManager::SMPManager() = default; + SMPManager::SMPManager() + { + StringView strCoreName(512); + strCoreName += "\\Properties\\Smp\\SchedulerClass"; + + cSMPCoreName.GetKey() = strCoreName; + cSMPCoreName.GetValue() = (UIntPtr)this; + + kcout << "newoskrnl: initializing " << strCoreName.CData() << endl; + } ///! @brief Default destructor. SMPManager::~SMPManager() = default; @@ -160,9 +172,9 @@ namespace Kernel // to avoid any null deref. if (!fThreadList[idx].Leak().Leak()->fStack) continue; - if (fThreadList[idx].Leak().Leak()->fStack->Rsp == 0) + if (fThreadList[idx].Leak().Leak()->fStack->SP == 0) continue; - if (fThreadList[idx].Leak().Leak()->fStack->Rbp == 0) + if (fThreadList[idx].Leak().Leak()->fStack->BP == 0) continue; fThreadList[idx].Leak().Leak()->Busy(true); diff --git a/Kernel/Sources/Semaphore.cxx b/Kernel/Sources/Semaphore.cxx index bef37fa8..ee89f482 100644 --- a/Kernel/Sources/Semaphore.cxx +++ b/Kernel/Sources/Semaphore.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Storage/AHCIDeviceInterface.cxx b/Kernel/Sources/Storage/AHCIDeviceInterface.cxx index 0366efe9..4b0aa23d 100644 --- a/Kernel/Sources/Storage/AHCIDeviceInterface.cxx +++ b/Kernel/Sources/Storage/AHCIDeviceInterface.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Storage/ATADeviceInterface.cxx b/Kernel/Sources/Storage/ATADeviceInterface.cxx index 8c45f31b..cc87491e 100644 --- a/Kernel/Sources/Storage/ATADeviceInterface.cxx +++ b/Kernel/Sources/Storage/ATADeviceInterface.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Storage/NVMEDeviceInterface.cxx b/Kernel/Sources/Storage/NVMEDeviceInterface.cxx index 9b2da7c2..f4f0f667 100644 --- a/Kernel/Sources/Storage/NVMEDeviceInterface.cxx +++ b/Kernel/Sources/Storage/NVMEDeviceInterface.cxx @@ -1,13 +1,26 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <StorageKit/NVME.hpp> +#include <StorageKit/NVME.hxx> namespace Kernel { + NVMEDeviceInterface::NVMEDeviceInterface(void (*Out)(MountpointInterface* outpacket), + void (*In)(MountpointInterface* inpacket), + void (*Cleanup)(void)) + : DeviceInterface(Out, In), fCleanup(Cleanup) + { + } + + NVMEDeviceInterface::~NVMEDeviceInterface() + { + if (fCleanup) + fCleanup(); + } + const char* NVMEDeviceInterface::Name() const { return ("NVMEDeviceInterface"); diff --git a/Kernel/Sources/Storage/SCSIDeviceInterface.cxx b/Kernel/Sources/Storage/SCSIDeviceInterface.cxx index 9ec5e4c9..14f58794 100644 --- a/Kernel/Sources/Storage/SCSIDeviceInterface.cxx +++ b/Kernel/Sources/Storage/SCSIDeviceInterface.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Stream.cxx b/Kernel/Sources/Stream.cxx index c83b6184..c2839cae 100644 --- a/Kernel/Sources/Stream.cxx +++ b/Kernel/Sources/Stream.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: Stream.cxx Purpose: Stream object diff --git a/Kernel/Sources/String.cxx b/Kernel/Sources/String.cxx index 8dd4b7bf..2ed52029 100644 --- a/Kernel/Sources/String.cxx +++ b/Kernel/Sources/String.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -22,7 +22,7 @@ namespace Kernel Size StringView::Length() const { - return rt_string_len(fData); + return fSz; } bool StringView::operator==(const StringView& rhs) const @@ -98,7 +98,7 @@ namespace Kernel if (!fmt) return ("-1"); - char* ret = (char*)Alloca(sizeof(char) * 8 + rt_string_len(fmt)); + char* ret = (char*)ALLOCA(sizeof(char) * 8 + rt_string_len(fmt)); if (!ret) return ("-1"); @@ -131,7 +131,7 @@ namespace Kernel ret[idx] = fmt[idx]; } - return ret; /* Copy that ret into a buffer, Alloca allocates to the stack */ + return ret; /* Copy that ret into a buffer, 'ALLOCA' allocates to the stack */ } const char* StringBuilder::FromBool(const char* fmt, bool i) @@ -140,7 +140,7 @@ namespace Kernel return ("?"); const char* boolean_expr = i ? "true" : "false"; - char* ret = (char*)Alloca((sizeof(char) * i) ? 4 : 5 + rt_string_len(fmt)); + char* ret = (char*)ALLOCA((sizeof(char) * i) ? 4 : 5 + rt_string_len(fmt)); if (!ret) return ("?"); @@ -189,7 +189,7 @@ namespace Kernel return ("?"); char* ret = - (char*)Alloca(sizeof(char) * rt_string_len(fmt2) + rt_string_len(fmt2)); + (char*)ALLOCA(sizeof(char) * rt_string_len(fmt2) + rt_string_len(fmt2)); if (!ret) return ("?"); @@ -214,22 +214,25 @@ namespace Kernel return ret; } - static void string_append(char* lhs, char* rhs, int cur) + STATIC void rt_string_append(Char* lhs, Char* rhs, Int cur) { - if (lhs && rhs) - { - SizeT sz_rhs = rt_string_len(rhs); - - if (sz_rhs == 0) - return; + SizeT sz_rhs = rt_string_len(rhs); + SizeT rhs_i = 0; - rt_copy_memory(rhs, lhs + cur, sz_rhs); + for (; rhs_i < sz_rhs; ++rhs_i) + { + lhs[rhs_i + cur] = rhs[rhs_i]; } + + lhs[rhs_i + cur] = 0; } StringView& StringView::operator+=(const Char* rhs) { - string_append(this->fData, const_cast<char*>(rhs), this->fCur); + if (rt_string_len(rhs) > this->Length()) + return *this; + + rt_string_append(this->fData, const_cast<Char*>(rhs), this->fCur); this->fCur += rt_string_len(rhs); return *this; @@ -237,11 +240,11 @@ namespace Kernel StringView& StringView::operator+=(const StringView& rhs) { - if (rt_string_len(rhs.fData) > rt_string_len(this->fData)) + if (rt_string_len(rhs.fData) > this->Length()) return *this; - string_append(this->fData, const_cast<char*>(rhs.fData), this->fCur); - this->fCur += rt_string_len(const_cast<char*>(rhs.fData)); + rt_string_append(this->fData, const_cast<Char*>(rhs.fData), this->fCur); + this->fCur += rt_string_len(const_cast<Char*>(rhs.fData)); return *this; } diff --git a/Kernel/Sources/ThreadLocalStorage.cxx b/Kernel/Sources/ThreadLocalStorage.cxx index 40a7a75f..245ffa1c 100644 --- a/Kernel/Sources/ThreadLocalStorage.cxx +++ b/Kernel/Sources/ThreadLocalStorage.cxx @@ -2,11 +2,13 @@ * ======================================================== * * Kernel - * Copyright Zeta Electronics Corporation, all rights reserved. + * Copyright ZKA Technologies, all rights reserved. * * ======================================================== */ +#include <NewKit/String.hpp> +#include <CFKit/Property.hpp> #include <KernelKit/ProcessScheduler.hxx> #include <KernelKit/ThreadLocalStorage.hxx> @@ -14,11 +16,13 @@ /***********************************************************************************/ /// @file ThreadLocalStorage.cxx -/// @brief TLS implementation in kernel. +/// @brief TLS inside the kernel. /***********************************************************************************/ using namespace Kernel; +Kernel::Property cTLSEnforceCheck; + /** * @brief Check for cookie inside TIB. * @param tib the TIB to check. @@ -33,7 +37,7 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) Encoder encoder; const char* tibAsBytes = encoder.AsBytes(tib); - kcout << "newoskrnl: Checking for a valid cookie...\r"; + kcout << "newoskrnl: checking for a valid cookie...\r"; return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && tibAsBytes[2] == kCookieMag2; @@ -44,18 +48,28 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) * @param stackPtr The call frame. * @return */ -EXTERN_C Void tls_check_syscall_impl(Kernel::VoidPtr TIB) noexcept +EXTERN_C Void tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept { - if (!TIB) - return; + if (!tib_ptr) + { + if (cTLSEnforceCheck.GetValue() == No) + { + return; + } + else + { + kcout << "newoskrnl: crashing because of an invalid TIB...\r"; + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + } + } - ThreadInformationBlock* tib = (ThreadInformationBlock*)TIB; + ThreadInformationBlock* tib_struct = (ThreadInformationBlock*)tib_ptr; - if (!tls_check_tib(tib)) + if (!tls_check_tib(tib_struct)) { kcout << "newoskrnl: crashing because of an invalid TIB...\r"; ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } - kcout << "newoskrnl: Verification succeeded! Keeping on...\r"; + kcout << "newoskrnl: Verification succeeded! staying alive...\r"; } diff --git a/Kernel/Sources/Timer.cxx b/Kernel/Sources/Timer.cxx index 38e58b70..ad43310d 100644 --- a/Kernel/Sources/Timer.cxx +++ b/Kernel/Sources/Timer.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/URL.cxx b/Kernel/Sources/URL.cxx index 8d31da7c..88328ea6 100644 --- a/Kernel/Sources/URL.cxx +++ b/Kernel/Sources/URL.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -20,17 +20,17 @@ namespace Kernel URL::~URL() = default; /// @brief internal and reserved protocols by kernel. - constexpr const char* kURLProtocols[] = { - "file", // Filesystem protocol - "mup", // Mahrouss update protocol - "param", // Mahrouss parameter protocol. + constexpr const Char* kURLProtocols[] = { + "file", // Filesystem protocol + "zup", // Zeta update protocol + "oscc", // Open System Configuration Connectivity. }; constexpr const int kUrlOutSz = 1; //! such as: :// constexpr const int kProtosCount = 3; constexpr const int kRangeSz = 4096; - ErrorOr<StringView> url_extract_location(const char* url) + ErrorOr<StringView> url_extract_location(const Char* url) { if (!url || *url == 0 || rt_string_len(url, kRangeSz) > kRangeSz) return ErrorOr<StringView>{-1}; @@ -62,7 +62,7 @@ namespace Kernel return ErrorOr<StringView>(view); } - ErrorOr<StringView> url_extract_protocol(const char* url) + ErrorOr<StringView> url_extract_protocol(const Char* url) { if (!url || *url == 0 || rt_string_len(url, kRangeSz) > kRangeSz) return ErrorOr<StringView>{-1}; @@ -74,7 +74,7 @@ namespace Kernel Ref<ErrorOr<StringView>> URL::Location() noexcept { - const char* src = fUrlView.Leak().CData(); + const Char* src = fUrlView.Leak().CData(); auto loc = url_extract_location(src); if (!loc) @@ -85,7 +85,7 @@ namespace Kernel Ref<ErrorOr<StringView>> URL::Protocol() noexcept { - const char* src = fUrlView.Leak().CData(); + const Char* src = fUrlView.Leak().CData(); auto loc = url_extract_protocol(src); if (!loc) diff --git a/Kernel/Sources/User.cxx b/Kernel/Sources/User.cxx new file mode 100644 index 00000000..68d0d5be --- /dev/null +++ b/Kernel/Sources/User.cxx @@ -0,0 +1,64 @@ +/* + * ======================================================== + * + * Kernel + * Copyright ZKA Technologies, all rights reserved. + * + * File: User.cpp + * Purpose: Permission selectors. + * + * ======================================================== + */ + +#include <KernelKit/User.hxx> +#include <NewKit/KernelCheck.hpp> + +/// bugs 0 + +namespace Kernel +{ + User::User(const Int32& sel, const Char* userName) + : fRing((RingKind)sel) + { + MUST_PASS(sel >= 0); + this->fUserName += userName; + } + + User::User(const RingKind& ringKind, const Char* userName) + : fRing(ringKind) + { + this->fUserName += userName; + } + + User::~User() = default; + + bool User::operator==(const User& lhs) + { + return lhs.fRing == this->fRing; + } + + bool User::operator!=(const User& lhs) + { + return lhs.fRing != this->fRing; + } + + const StringView User::Name() noexcept + { + return this->fUserName; + } + + const RingKind& User::Ring() noexcept + { + return this->fRing; + } + + Bool User::IsStdUser() noexcept + { + return this->Ring() == RingKind::kRingStdUser; + } + + Bool User::IsSuperUser() noexcept + { + return this->Ring() == RingKind::kRingSuperUser; + } +} // namespace Kernel diff --git a/Kernel/Sources/Utils.cxx b/Kernel/Sources/Utils.cxx index 37269ca1..eeac3f93 100644 --- a/Kernel/Sources/Utils.cxx +++ b/Kernel/Sources/Utils.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -37,7 +37,7 @@ namespace Kernel { if (len > _len) { - break; + return 0; } ++len; @@ -48,15 +48,14 @@ namespace Kernel Size rt_string_len(const Char* ptr) { - if (!ptr) + if (*ptr == 0) return 0; SizeT cnt = 0; - while (*ptr != (Char)0) + while (ptr[cnt] != (Char)0) { - ++ptr; - ++cnt; + cnt++; } return cnt; diff --git a/Kernel/Sources/Variant.cxx b/Kernel/Sources/Variant.cxx index 7630f5db..7dc71df5 100644 --- a/Kernel/Sources/Variant.cxx +++ b/Kernel/Sources/Variant.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -12,13 +12,17 @@ namespace Kernel { switch (fKind) { + case VariantKind::kJson: + return ("Class:{Json}"); case VariantKind::kString: return ("Class:{String}"); - case VariantKind::kPointer: - return ("Memory:{Pointer}"); + case VariantKind::kBlob: + return ("Class:{Blob}"); default: - return ("Memory:{Undefined}"); + return ("Class:{Null}"); } } + /// @brief Leak variant's instance. + VoidPtr Variant::Leak() { return fPtr; } } // namespace Kernel diff --git a/Kernel/Sources/compile_flags.txt b/Kernel/Sources/compile_flags.txt index 1f54e6fb..b02c5e3d 100644 --- a/Kernel/Sources/compile_flags.txt +++ b/Kernel/Sources/compile_flags.txt @@ -3,5 +3,5 @@ -std=c++20 -I../ -I$(HOME)/ --D__FSKIT_NEWFS__ +-D__FSKIT_USE_NEWFS__ -D__NEWOS_AMD64__ diff --git a/Kernel/StorageKit/AHCI.hpp b/Kernel/StorageKit/AHCI.hpp index af4a1327..f84e175e 100644 --- a/Kernel/StorageKit/AHCI.hpp +++ b/Kernel/StorageKit/AHCI.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -28,6 +28,6 @@ namespace Kernel const char* Name() const override; private: - void (*fCleanup)(void); + void (*fCleanup)(void) = {nullptr}; }; -} // namespace Kernel
\ No newline at end of file +} // namespace Kernel diff --git a/Kernel/StorageKit/ATA.hpp b/Kernel/StorageKit/ATA.hpp index 5c03f7ae..0862c56d 100644 --- a/Kernel/StorageKit/ATA.hpp +++ b/Kernel/StorageKit/ATA.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -34,6 +34,6 @@ namespace Kernel const char* Name() const override; private: - void (*fCleanup)(void); + void (*fCleanup)(void) = { nullptr }; }; -} // namespace Kernel
\ No newline at end of file +} // namespace Kernel diff --git a/Kernel/StorageKit/NVME.hpp b/Kernel/StorageKit/NVME.hxx index c7ff0e66..f1601149 100644 --- a/Kernel/StorageKit/NVME.hpp +++ b/Kernel/StorageKit/NVME.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -12,21 +12,14 @@ namespace Kernel { - class NVMEDeviceInterface : public DeviceInterface<MountpointInterface*> + class NVMEDeviceInterface final : public DeviceInterface<MountpointInterface*> { public: explicit NVMEDeviceInterface(void (*Out)(MountpointInterface* outpacket), void (*In)(MountpointInterface* inpacket), - void (*Cleanup)(void)) - : DeviceInterface(Out, In), fCleanup(Cleanup) - { - } + void (*Cleanup)(void)); - virtual ~NVMEDeviceInterface() - { - if (fCleanup) - fCleanup(); - } + ~NVMEDeviceInterface() override; public: NVMEDeviceInterface& operator=(const NVMEDeviceInterface&) = default; @@ -38,6 +31,6 @@ namespace Kernel OwnPtr<MountpointInterface*> operator()(UInt32 dmaLow, UInt32 dmaHigh, SizeT sz); private: - void (*fCleanup)(void); + void (*fCleanup)(void) = {nullptr}; }; } // namespace Kernel diff --git a/Kernel/StorageKit/PRDT.hpp b/Kernel/StorageKit/PRDT.hpp index 522e96fb..daf465d4 100644 --- a/Kernel/StorageKit/PRDT.hpp +++ b/Kernel/StorageKit/PRDT.hpp @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -8,7 +8,7 @@ #include <KernelKit/PCI/Dma.hpp> #include <KernelKit/PCI/Iterator.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> #define kPrdtTransferSize (sizeof(Kernel::UShort)) diff --git a/Kernel/StorageKit/SCSI.hxx b/Kernel/StorageKit/SCSI.hxx index 646b1844..5a22af84 100644 --- a/Kernel/StorageKit/SCSI.hxx +++ b/Kernel/StorageKit/SCSI.hxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/StorageKit/Storage.hpp b/Kernel/StorageKit/Storage.hpp index a374c6e1..aa9e335e 100644 --- a/Kernel/StorageKit/Storage.hpp +++ b/Kernel/StorageKit/Storage.hpp @@ -1,16 +1,22 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #pragma once -#include <NewKit/Defines.hpp> -#include <StorageKit/NVME.hpp> -#include <StorageKit/AHCI.hpp> -#include <StorageKit/SCSI.hxx> +#define kDriveSectorSizeHDD (512) +#define kDriveSectorSizeSSD (4096) +#define kDriveSectorSizeOptical (2048) -#define kDriveSectorSizeHDD (512) -#define kDriveSectorSizeSSD (4096) -#define kDriveSectorSizeCDROM (2048) +namespace Kernel +{ + template <typename T> + class DeviceInterface; + + class NVMEDeviceInterface; + class AHCIDeviceInterface; + class ATADeviceInterface; + class SCSIDeviceInterface; +} // namespace Kernel diff --git a/Kernel/amd64-efi.make b/Kernel/amd64-efi.make index 7624c6fd..a6bd3772 100644 --- a/Kernel/amd64-efi.make +++ b/Kernel/amd64-efi.make @@ -1,12 +1,12 @@ ################################################## -# (C) Zeta Electronics Corporation, all rights reserved. -# This is the microkernel makefile. +# (C) ZKA Technologies, all rights reserved. +# This is the newoskrnl's makefile. ################################################## CC = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld -CCFLAGS = -c -fPIC -ffreestanding -D__NEWOS_AMD64__ -mno-red-zone -fno-rtti -fno-exceptions \ - -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I./ +CCFLAGS = -fshort-wchar -c -fPIC -ffreestanding -D__NEWOS_AMD64__ -mno-red-zone -fno-rtti -fno-exceptions \ + -std=c++20 -D__NEWOS_SUPPORT_NX__ -I../Vendor -D__FSKIT_USE_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I./ ASM = nasm @@ -59,8 +59,8 @@ newos-amd64-epm: clean $(wildcard HALKit/AMD64/*.s) $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalSMPCoreManager.asm - $(ASM) $(ASMFLAGS) HALKit/AMD64/HalNewBoot.asm - $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInstallTIB.asm + $(ASM) $(ASMFLAGS) HALKit/AMD64/HalBoot.asm + $(ASM) $(ASMFLAGS) HALKit/AMD64/HalUtils.asm $(MOVEALL) OBJCOPY=x86_64-w64-mingw32-objcopy diff --git a/Kernel/arm64-cb.make b/Kernel/arm64-efi.make index 1d87edf6..60ccb5de 100644 --- a/Kernel/arm64-cb.make +++ b/Kernel/arm64-efi.make @@ -1,14 +1,15 @@ ################################################## -# (C) Zeta Electronics Corporation, all rights reserved. +# (C) ZKA Technologies, all rights reserved. # This is the microkernel makefile. ################################################## -CC = arm-none-eabi-g++ -march=armv8-a -LD = arm-none-eabi-ld -CCFLAGS = -c -fPIC -ffreestanding -D__NEWOS_ARM64__ -fno-rtti -fno-exceptions -I./ \ - -std=c++20 -D__FSKIT_NEWFS__ -D__ZETA_MACHINE__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ +CC = clang++ +LD = lld-link +CCFLAGS = -fshort-wchar -c -ffreestanding -MMD -mno-red-zone -D__NEWOS_ARM64__ -fno-rtti -fno-exceptions -I./ \ + -target aarch64-unknown-windows \ + -std=c++20 -D__FSKIT_USE_NEWFS__ -D__ZETA_MACHINE__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -ASM = arm-none-eabi-as -march=armv8-a +ASM = clang++ DISKDRIVER = -D__FLASH_MEM__ @@ -22,7 +23,7 @@ endif COPY = cp -LDFLAGS = -e __ImageStart +LDFLAGS = -subsystem:efi_application -entry:hal_init_platform /nodefaultlib LDOBJ = Objects/*.obj # This file is the kernel, responsible of task management and memory. @@ -50,7 +51,7 @@ OBJCOPY=x86_64-w64-mingw32-objcopy .PHONY: link-arm64-epm link-arm64-epm: - $(LD) $(LDFLAGS) $(LDOBJ) -o $(KERNEL) + $(LD) $(LDFLAGS) $(LDOBJ) /out:$(KERNEL) .PHONY: all all: newos-arm64-epm link-arm64-epm diff --git a/Kernel/compile_flags.txt b/Kernel/compile_flags.txt index de13f8f6..4087caba 100644 --- a/Kernel/compile_flags.txt +++ b/Kernel/compile_flags.txt @@ -4,3 +4,6 @@ -I./ -I$(HOME)/ -D__NEWOS_AMD64__ +-I../Vendor +-D__x86_64__ +-D__ED__ diff --git a/Kernel/power64-cb.make b/Kernel/power64-cb.make new file mode 100644 index 00000000..f35df9ba --- /dev/null +++ b/Kernel/power64-cb.make @@ -0,0 +1,4 @@ +################################################## +# (C) ZKA Technologies, all rights reserved. +# This is the microkernel makefile. +################################################## diff --git a/Kernel/riscv64-cb.make b/Kernel/riscv64-cb.make new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/Kernel/riscv64-cb.make |
