diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-10 15:41:08 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-10 15:41:08 +0100 |
| commit | 5468ca71a59c9e24c1d392554e8f97f0c1705394 (patch) | |
| tree | 1e8af47da852d4ad02a2ea48a967694c7bfc19c3 /Public/Kits/System.Core | |
| parent | 94d7585ae766d777f41d07b1a98051d12a6a0256 (diff) | |
Kernel: Reworked StorageKit to add AHCI support.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Public/Kits/System.Core')
| -rw-r--r-- | Public/Kits/System.Core/.gitkeep | 0 | ||||
| -rw-r--r-- | Public/Kits/System.Core/Containers/XIFF.hxx | 40 | ||||
| -rw-r--r-- | Public/Kits/System.Core/CoreAPI.hxx | 48 | ||||
| -rw-r--r-- | Public/Kits/System.Core/FileAPI.hxx | 40 | ||||
| -rw-r--r-- | Public/Kits/System.Core/HcHeapAPI.h | 23 | ||||
| -rw-r--r-- | Public/Kits/System.Core/HeapAPI.cxx | 34 | ||||
| -rw-r--r-- | Public/Kits/System.Core/HeapAPI.hxx | 64 | ||||
| -rw-r--r-- | Public/Kits/System.Core/Makefile | 20 | ||||
| -rw-r--r-- | Public/Kits/System.Core/System.hxx | 18 | ||||
| -rw-r--r-- | Public/Kits/System.Core/ThreadAPI.hxx | 36 | ||||
| -rw-r--r-- | Public/Kits/System.Core/compile_flags.txt | 4 |
11 files changed, 327 insertions, 0 deletions
diff --git a/Public/Kits/System.Core/.gitkeep b/Public/Kits/System.Core/.gitkeep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/Public/Kits/System.Core/.gitkeep diff --git a/Public/Kits/System.Core/Containers/XIFF.hxx b/Public/Kits/System.Core/Containers/XIFF.hxx new file mode 100644 index 00000000..28c25bf9 --- /dev/null +++ b/Public/Kits/System.Core/Containers/XIFF.hxx @@ -0,0 +1,40 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#ifndef __XIFF__ +#define __XIFF__ + +/** --------------------------------------------------- + + * THIS FILE CONTAINS CODE FOR THE eXtended Information File Format. + * XIFF is used to make setup programs/audio/video files. + +------------------------------------------------------- */ + +#include <System.Core/CoreAPI.hxx> + +/// @brief four-character code for XIFF. +#define kFourCCLength_XIFF 4 + +/*** + * @brief Generic XIFF header + * Used by XIFF based containers. + */ + +struct PACKED XiffHeader final { + BYTE f_Mag[kFourCCLength_XIFF]; // XIFF string (includes \0) + DWORD f_Size; // overall size of header (XiffHeader) in bytes + DWORD f_FormatType; // format type. generic + BYTE f_SpecificMag[4]; // The sub header magic + DWORD f_SpecificSize; // length of the format data + DWORD f_SpecificFormatType; // format type. generic +}; + +#define kXIFFContainerVideo "XVFF" +#define kXIFFContainerAudio "XAFF" +#define kXIFFContainerInstaller "XnFF" +#define kXIFFContainerGeneric "XIFF" +#define kXIFFContainerBinary "XEFF" + +#endif // ifndef __XIFF__ diff --git a/Public/Kits/System.Core/CoreAPI.hxx b/Public/Kits/System.Core/CoreAPI.hxx new file mode 100644 index 00000000..1cd48442 --- /dev/null +++ b/Public/Kits/System.Core/CoreAPI.hxx @@ -0,0 +1,48 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#ifndef __cplusplus +#error This API is meant to be used with C++ +#endif + +#ifdef CA_MUST_PASS +#undef CA_MUST_PASS +#endif + +// unused by user side, it's a kernel thing. +#define CA_MUST_PASS(e) ((void)e) + +#define CA_EXTERN_C extern "C" + +#define CA_STDCALL __attribute__((stdcall)) +#define CA_CDECL __attribute__((cdecl)) +#define CA_MSCALL __attribute__((ms_abi)) + +typedef __UINT8_TYPE__ BYTE; +typedef __UINT16_TYPE__ WORD; +typedef __UINT32_TYPE__ DWORD; +typedef __UINT64_TYPE__ QWORD; + +typedef __WCHAR_TYPE__ WCHAR; +typedef WCHAR* PWCHAR; + +#ifdef __x86_64__ +# define _M_AMD64 2 +#endif + +#ifdef __aarch64__ +# define _M_AARCH64 3 +#endif + +#ifdef __powerpc64__ +# define _M_PPC64 4 +#endif + +#ifdef __64x0__ +# define _M_64000 5 +#endif diff --git a/Public/Kits/System.Core/FileAPI.hxx b/Public/Kits/System.Core/FileAPI.hxx new file mode 100644 index 00000000..66ecef22 --- /dev/null +++ b/Public/Kits/System.Core/FileAPI.hxx @@ -0,0 +1,40 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#ifndef _SYSTEM_KIT_HCORE_FILE_HPP +#define _SYSTEM_KIT_HCORE_FILE_HPP + +#include <CompilerKit/CompilerKit.hpp> +#include <NewKit/Defines.hpp> + +using namespace HCore; + +/// @brief SOM class, translated to C++ + +class HFile final { + public: + explicit HFile(const char *path); + ~HFile(); + + public: + HCORE_COPY_DEFAULT(HFile); + + public: + voidPtr Read(SizeT off, SizeT sz); + void Write(voidPtr buf, SizeT off, SizeT sz); + void Seek(SizeT off); + voidPtr Read(SizeT sz); + void Write(voidPtr buf, SizeT sz); + void Rewind(); + + public: + const char *MIME(); + void MIME(const char *mime); +}; + +typedef HFile *HFilePtr; + +#endif // ifndef _SYSTEM_KIT_HCORE_FILE_HPP diff --git a/Public/Kits/System.Core/HcHeapAPI.h b/Public/Kits/System.Core/HcHeapAPI.h new file mode 100644 index 00000000..20078ce7 --- /dev/null +++ b/Public/Kits/System.Core/HcHeapAPI.h @@ -0,0 +1,23 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#pragma once + +#ifdef __cplusplus +#define EXTERN_C extern "C" +#else +#define EXTERN_C extern +#endif // ifdef __cplusplus + +typedef struct HcObject { + void(*Release)(void); + void(*Invoke)(void); + void(*QueryInterface)(void); +} *HcObjectPtr; + +EXTERN_C HcObjectPtr HcGetProcessHeap(void); +EXTERN_C void* HcAllocateProcessHeap(HcObjectPtr refObj, long long int sz, int flags); +EXTERN_C void HcFreeProcessHeap(HcObjectPtr refObj, void* ptr); +EXTERN_C long long int HcProcessHeapSize(HcObjectPtr refObj, void* ptr); +EXTERN_C long long int HcProcessHeapExists(HcObjectPtr refObj, void* ptr);
\ No newline at end of file diff --git a/Public/Kits/System.Core/HeapAPI.cxx b/Public/Kits/System.Core/HeapAPI.cxx new file mode 100644 index 00000000..f59e0b1b --- /dev/null +++ b/Public/Kits/System.Core/HeapAPI.cxx @@ -0,0 +1,34 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include <System.Core/HeapAPI.hxx> +#include <System.Core/HcHeapAPI.h> + +using namespace HCore; + +STATIC HcObjectPtr kObjectHeap; + +HHeap* HHeap::Shared() noexcept { + static HHeap* heap = nullptr; + + if (!heap) { + heap = new HHeap(); + kObjectHeap = HcGetProcessHeap(); + } + + return heap; +} + +void HHeap::Delete(HHeapPtr me) noexcept { HcFreeProcessHeap(kObjectHeap, me); } + +SizeT HHeap::Size(HHeapPtr me) noexcept { return HcProcessHeapSize(kObjectHeap, me); } + +HHeapPtr HHeap::New(const SizeT &sz, const Int32 flags) { + SizeT _sz = sz; + if (!_sz) ++_sz; + + return HcAllocateProcessHeap(kObjectHeap, _sz, flags); +}
\ No newline at end of file diff --git a/Public/Kits/System.Core/HeapAPI.hxx b/Public/Kits/System.Core/HeapAPI.hxx new file mode 100644 index 00000000..9391bc4f --- /dev/null +++ b/Public/Kits/System.Core/HeapAPI.hxx @@ -0,0 +1,64 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include <CompilerKit/CompilerKit.hpp> +#include <NewKit/Defines.hpp> + +/// @brief SOM class, translated to C++ + +using namespace HCore; + +class HMemoryException; + +typedef VoidPtr HHeapPtr; + +enum { + kHeapExpandable = 2, + kHeapNoExecute = 4, + kHeapShared = 6, + kHeapReadOnly = 8, + kHeapNoFlags = 0 +}; + +class HHeap final { + private: + explicit HHeap(); + + public: + ~HHeap(); + + public: + HCORE_COPY_DEFAULT(HHeap); + + public: + static HHeap *Shared() noexcept; + + public: + void Delete(HHeapPtr me) noexcept; + SizeT Size(HHeapPtr me) noexcept; + HHeapPtr New(const SizeT &sz, const Int32 flags = kHeapNoFlags); +}; + +class HMemoryException final { + public: + explicit HMemoryException() = default; + ~HMemoryException() = default; + + public: + HCORE_COPY_DEFAULT(HMemoryException); + + public: + const char *Name(); + const char *Reason(); + + private: + const char *mReason{"HeapAPI: Memory Exception!"}; + + private: + friend HHeap; +}; diff --git a/Public/Kits/System.Core/Makefile b/Public/Kits/System.Core/Makefile new file mode 100644 index 00000000..d710b2e8 --- /dev/null +++ b/Public/Kits/System.Core/Makefile @@ -0,0 +1,20 @@ +################################################## +# ; (C) Mahrouss Logic, 2024, all rights reserved. +# This is the System.Graphics Makefile. +################################################## + +CC=x86_64-w64-mingw32-g++ +CCFLAGS=-shared -ffreestanding -fno-rtti -fno-exceptions -std=c++20 +OUTPUT=System.Core.dll + +.PHONY: build-gkit +build-gkit: + $(CC) -I../ -I$(HOME) -I../../../Private/ $(CCFLAGS) *.cxx -o $(OUTPUT) + +.PHONY: all +all: build-gkit + @echo "[System.Core.dll] Build done." + +.PHONY: clean +clean: + rm -f *.o diff --git a/Public/Kits/System.Core/System.hxx b/Public/Kits/System.Core/System.hxx new file mode 100644 index 00000000..97d4bdac --- /dev/null +++ b/Public/Kits/System.Core/System.hxx @@ -0,0 +1,18 @@ +/*** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#pragma once + +/** --------------------------------------------------- + + * THIS FILE CONTAINS CODE FOR THE STANDARD HCORE API. + +------------------------------------------------------- */ + +#include <System.Core/CoreAPI.hxx> +#include <System.Core/FileAPI.hxx> +#include <System.Core/HeapAPI.hxx> +#include <System.Core/ThreadAPI.hxx> + +using namespace HCore; diff --git a/Public/Kits/System.Core/ThreadAPI.hxx b/Public/Kits/System.Core/ThreadAPI.hxx new file mode 100644 index 00000000..ec15a64c --- /dev/null +++ b/Public/Kits/System.Core/ThreadAPI.hxx @@ -0,0 +1,36 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +// +// Created by Amlal on 1/27/24. +// + +#ifndef __THREAD_API__ +#define __THREAD_API__ + +#include <NewKit/Defines.hpp> + +namespace HCore { +/// @brief Thread Information Block for Local Storage. +/// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64) +struct ThreadInformationBlock final { + const Char Name[255]; // Module Name + const UIntPtr StartAddress; // Start Address + const UIntPtr StartHeap; // Allocation Heap + const UIntPtr StartStack; // Stack Pointer. + const Int32 Arch; // Architecture and/or platform. +}; + +enum { + kPC_IA64, + kPC_AMD64 = kPC_IA64, + kPC_ARM, + kMACS_64x0, + kMACS_32x0, +}; +} // namespace HCore + +#endif // __THREAD_API__ diff --git a/Public/Kits/System.Core/compile_flags.txt b/Public/Kits/System.Core/compile_flags.txt new file mode 100644 index 00000000..6e721e73 --- /dev/null +++ b/Public/Kits/System.Core/compile_flags.txt @@ -0,0 +1,4 @@ +-I./ +-I../ +-I../../../Private +-std=c++20 |
