From 7e5be1572c043484293ee0cdd840dd41f54e87ee Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 29 Mar 2024 17:01:55 +0100 Subject: Kernel and SystemLib: See below. What has been done: - Rename most System.Core to SystemLib. - Reworked it's API and the concept of ObjectRef to become the ApplicationRef object. - Remove unused ODF and XIFF file format from tree, ODF will be part of the text editing program. - Update Readme for SystemLib. - Add Support folder on NewFS partitions. What is next: - NewFS filesystem support. - Program loading. - Preemptive scheduler on non-SMP systems using timers. Signed-off-by: Amlal El Mahrouss --- .vscode/c_cpp_properties.json | 2 + Private/NewKit/Application.hxx | 29 +++ Private/ObjectKit/ObjectKit.hxx | 35 ---- Private/Root/Frameworks/.gitkeep | 0 Private/Root/Support/.gitkeep | 0 Private/Root/Users/.USERHASH | 0 Private/Root/Users/User.script | 3 + Public/Developer/CxxLib/.gitkeep | 0 Public/Developer/CxxLib/Sources/New+Delete.cxx | 27 +++ Public/Developer/DriverLib/.gitkeep | 0 Public/Developer/System.Containers/.gitkeep | 0 Public/Developer/System.Containers/Headers/ODF.h | 41 ---- Public/Developer/System.Containers/Headers/XIFF.h | 62 ------ Public/Developer/System.Core/.gitkeep | 0 .../System.Core/AMD64/HCoreAssemblyRoutines.s | 24 --- Public/Developer/System.Core/ARM64/.gitkeep | 0 Public/Developer/System.Core/Headers/Defines.h | 207 --------------------- Public/Developer/System.Core/Headers/Dialog.h | 16 -- Public/Developer/System.Core/Headers/File.h | 44 ----- Public/Developer/System.Core/Headers/Heap.h | 38 ---- Public/Developer/System.Core/Headers/Hint.h | 18 -- Public/Developer/System.Core/Headers/Thread.h | 43 ----- Public/Developer/System.Core/Headers/TrueType.h | 32 ---- Public/Developer/System.Core/Headers/Window.h | 153 --------------- Public/Developer/System.Core/Makefile | 23 --- Public/Developer/System.Core/RISCV/.gitkeep | 0 Public/Developer/System.Core/ReadMe.md | 8 - Public/Developer/System.Core/Sources/App.c | 20 -- Public/Developer/System.Core/Sources/Heap.c | 42 ----- Public/Developer/System.Core/Sources/Start.c | 15 -- Public/Developer/System.Core/Sources/Window.c | 70 ------- Public/Developer/System.Core/compile_flags.txt | 4 - Public/Developer/System.Cxx/.gitkeep | 0 Public/Developer/System.Cxx/Sources/New+Delete.cxx | 27 --- Public/Developer/System.Driver/.gitkeep | 0 Public/Developer/SystemLib/.gitkeep | 0 .../SystemLib/AMD64/HCoreAssemblyRoutines.s | 24 +++ Public/Developer/SystemLib/ARM64/.gitkeep | 0 Public/Developer/SystemLib/Headers/Defines.h | 196 +++++++++++++++++++ Public/Developer/SystemLib/Headers/Dialog.h | 16 ++ Public/Developer/SystemLib/Headers/File.h | 44 +++++ Public/Developer/SystemLib/Headers/Heap.h | 38 ++++ Public/Developer/SystemLib/Headers/Hint.h | 18 ++ Public/Developer/SystemLib/Headers/Thread.h | 43 +++++ Public/Developer/SystemLib/Headers/TrueType.h | 31 +++ Public/Developer/SystemLib/Headers/Window.h | 153 +++++++++++++++ Public/Developer/SystemLib/Makefile | 23 +++ Public/Developer/SystemLib/RISCV/.gitkeep | 0 Public/Developer/SystemLib/ReadMe.md | 14 ++ Public/Developer/SystemLib/Sources/Application.c | 25 +++ .../Developer/SystemLib/Sources/ApplicationStart.c | 14 ++ Public/Developer/SystemLib/Sources/Heap.c | 42 +++++ Public/Developer/SystemLib/Sources/Window.c | 70 +++++++ Public/Developer/SystemLib/compile_flags.txt | 4 + 54 files changed, 816 insertions(+), 922 deletions(-) create mode 100644 Private/NewKit/Application.hxx delete mode 100644 Private/ObjectKit/ObjectKit.hxx delete mode 100644 Private/Root/Frameworks/.gitkeep create mode 100644 Private/Root/Support/.gitkeep delete mode 100644 Private/Root/Users/.USERHASH create mode 100644 Private/Root/Users/User.script create mode 100644 Public/Developer/CxxLib/.gitkeep create mode 100644 Public/Developer/CxxLib/Sources/New+Delete.cxx create mode 100644 Public/Developer/DriverLib/.gitkeep delete mode 100644 Public/Developer/System.Containers/.gitkeep delete mode 100644 Public/Developer/System.Containers/Headers/ODF.h delete mode 100644 Public/Developer/System.Containers/Headers/XIFF.h delete mode 100644 Public/Developer/System.Core/.gitkeep delete mode 100644 Public/Developer/System.Core/AMD64/HCoreAssemblyRoutines.s delete mode 100644 Public/Developer/System.Core/ARM64/.gitkeep delete mode 100644 Public/Developer/System.Core/Headers/Defines.h delete mode 100644 Public/Developer/System.Core/Headers/Dialog.h delete mode 100644 Public/Developer/System.Core/Headers/File.h delete mode 100644 Public/Developer/System.Core/Headers/Heap.h delete mode 100644 Public/Developer/System.Core/Headers/Hint.h delete mode 100644 Public/Developer/System.Core/Headers/Thread.h delete mode 100644 Public/Developer/System.Core/Headers/TrueType.h delete mode 100644 Public/Developer/System.Core/Headers/Window.h delete mode 100644 Public/Developer/System.Core/Makefile delete mode 100644 Public/Developer/System.Core/RISCV/.gitkeep delete mode 100644 Public/Developer/System.Core/ReadMe.md delete mode 100644 Public/Developer/System.Core/Sources/App.c delete mode 100644 Public/Developer/System.Core/Sources/Heap.c delete mode 100644 Public/Developer/System.Core/Sources/Start.c delete mode 100644 Public/Developer/System.Core/Sources/Window.c delete mode 100644 Public/Developer/System.Core/compile_flags.txt delete mode 100644 Public/Developer/System.Cxx/.gitkeep delete mode 100644 Public/Developer/System.Cxx/Sources/New+Delete.cxx delete mode 100644 Public/Developer/System.Driver/.gitkeep create mode 100644 Public/Developer/SystemLib/.gitkeep create mode 100644 Public/Developer/SystemLib/AMD64/HCoreAssemblyRoutines.s create mode 100644 Public/Developer/SystemLib/ARM64/.gitkeep create mode 100644 Public/Developer/SystemLib/Headers/Defines.h create mode 100644 Public/Developer/SystemLib/Headers/Dialog.h create mode 100644 Public/Developer/SystemLib/Headers/File.h create mode 100644 Public/Developer/SystemLib/Headers/Heap.h create mode 100644 Public/Developer/SystemLib/Headers/Hint.h create mode 100644 Public/Developer/SystemLib/Headers/Thread.h create mode 100644 Public/Developer/SystemLib/Headers/TrueType.h create mode 100644 Public/Developer/SystemLib/Headers/Window.h create mode 100644 Public/Developer/SystemLib/Makefile create mode 100644 Public/Developer/SystemLib/RISCV/.gitkeep create mode 100644 Public/Developer/SystemLib/ReadMe.md create mode 100644 Public/Developer/SystemLib/Sources/Application.c create mode 100644 Public/Developer/SystemLib/Sources/ApplicationStart.c create mode 100644 Public/Developer/SystemLib/Sources/Heap.c create mode 100644 Public/Developer/SystemLib/Sources/Window.c create mode 100644 Public/Developer/SystemLib/compile_flags.txt diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index bc577a82..08cf70c4 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -5,6 +5,7 @@ "includePath": [ "${workspaceFolder}/Private/**", "${workspaceFolder}/Private/NewBoot/**", + "${workspaceFolder}/Public/Developer/SystemLib/**", "${workspaceFolder}/Public/Developer/**" ], "defines": [ @@ -34,6 +35,7 @@ "includePath": [ "${workspaceFolder}/Private/**", "${workspaceFolder}/Private/NewBoot/**", + "${workspaceFolder}/Public/Developer/SystemLib/**", "${workspaceFolder}/Public/Developer/**" ], "defines": [ diff --git a/Private/NewKit/Application.hxx b/Private/NewKit/Application.hxx new file mode 100644 index 00000000..292bb434 --- /dev/null +++ b/Private/NewKit/Application.hxx @@ -0,0 +1,29 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +/// +/// @brief Main application object, given by the OS to interact with the OS. +/// @file Application.hxx +/// @author Amlal EL Mahrouss +/// + +#include +#include + +/// \brief Application Interface. +/// \author Amlal El Mahrouss +typedef struct Application final { + /// @brief Releases the object exit the process on main object. + NewOS::Void(*Release)(struct Application* Self, NewOS::Int32 ExitCode); + /// @brief Invoke a function from the application object. + NewOS::IntPtr(*Invoke)(struct Application* Self, NewOS::Int32 Sel, ...); + /// @brief Query a new application object from a GUID. + NewOS::Void(*Query)(struct Application* Self, NewOS::VoidPtr* Dst, NewOS::SizeT SzDst, NewOS::XRN::GUIDSequence GuidOf); +} Application, *ApplicationRef; + +#define object_cast reinterpret_cast diff --git a/Private/ObjectKit/ObjectKit.hxx b/Private/ObjectKit/ObjectKit.hxx deleted file mode 100644 index 384bf145..00000000 --- a/Private/ObjectKit/ObjectKit.hxx +++ /dev/null @@ -1,35 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include -#include - -#define kObjectGlobalNamespace ":\\" - -enum { - kObjectTypeGeneric, - kObjectTypeFile, - kObjectTypeDevice, - kObjectTypeNetwork, - kObjectTypeInvalid, - kObjectTypeCount = 5, -}; - -/// \brief Object handle. -/// \author Amlal El Mahrouss -typedef struct Object final { - NewOS::Char ObjectName[255]; - NewOS::Int32 ObjectType; - NewOS::Char ObjectNamespace[255]; - - NewOS::Void(*Release)(struct Object* Self); - NewOS::IntPtr(*Invoke)(struct Object* Self, NewOS::Int32 Sel, ...); - NewOS::Void(*Query)(struct Object* Self, NewOS::VoidPtr* Dst, NewOS::SizeT SzDst, NewOS::XRN::GUIDSequence GuidOf); -} *ObjectRef; - -#define object_cast reinterpret_cast diff --git a/Private/Root/Frameworks/.gitkeep b/Private/Root/Frameworks/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Private/Root/Support/.gitkeep b/Private/Root/Support/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Private/Root/Users/.USERHASH b/Private/Root/Users/.USERHASH deleted file mode 100644 index e69de29b..00000000 diff --git a/Private/Root/Users/User.script b/Private/Root/Users/User.script new file mode 100644 index 00000000..09cecb8b --- /dev/null +++ b/Private/Root/Users/User.script @@ -0,0 +1,3 @@ +# User script + +Guest: true; diff --git a/Public/Developer/CxxLib/.gitkeep b/Public/Developer/CxxLib/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Public/Developer/CxxLib/Sources/New+Delete.cxx b/Public/Developer/CxxLib/Sources/New+Delete.cxx new file mode 100644 index 00000000..c95da3e1 --- /dev/null +++ b/Public/Developer/CxxLib/Sources/New+Delete.cxx @@ -0,0 +1,27 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include + +typedef SizeType size_t; + +void* operator new[](size_t sz) { + if (sz == 0) ++sz; + + return RtAllocateProcessPtr(sz, kStandardAllocation); +} + +void* operator new(size_t sz) { + if (sz == 0) ++sz; + + return RtAllocateProcessPtr(sz, kArrayAllocation); +} + +void operator delete[](void* ptr) { + if (ptr == nullptr) return; + + RtFreeProcessPtr(ptr); +} \ No newline at end of file diff --git a/Public/Developer/DriverLib/.gitkeep b/Public/Developer/DriverLib/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Public/Developer/System.Containers/.gitkeep b/Public/Developer/System.Containers/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Public/Developer/System.Containers/Headers/ODF.h b/Public/Developer/System.Containers/Headers/ODF.h deleted file mode 100644 index 48dc1e1e..00000000 --- a/Public/Developer/System.Containers/Headers/ODF.h +++ /dev/null @@ -1,41 +0,0 @@ -/** =========================================== - (C) Mahrouss Logic - ===========================================*/ - -#ifndef __ODF__ -#define __ODF__ - -#include - -/** - * @brief Open Document Format - * @file ODF.hxx - */ - -/// @brief four-character code for ODF. -#define kFourCCLength_ODF 4 - -/// @brief Document file header. -typedef struct ODFFileHeader { - CharacterTypeUTF8 f_Ident[kFourCCLength_ODF]; - - Int32Type f_DocumentKind; - Int32Type f_DocumentSize; - - Int64Type f_MetaForkOffset; - Int64Type f_DocumentForkOffset; - - CharacterTypeUTF8 f_Padding[4]; -} PACKED ODFFileHeader; - -/// @brief ODF Fork header -typedef struct ODFForkHeader { - CharacterTypeUTF8 f_MetadataName[255]; - - Int32Type f_MetadataKind; - Int32Type f_MetadataSize; - - CharacterTypeUTF8 f_Padding; -} PACKED ODFForkHeader; - -#endif // !__ODF__ \ No newline at end of file diff --git a/Public/Developer/System.Containers/Headers/XIFF.h b/Public/Developer/System.Containers/Headers/XIFF.h deleted file mode 100644 index dd4880cd..00000000 --- a/Public/Developer/System.Containers/Headers/XIFF.h +++ /dev/null @@ -1,62 +0,0 @@ -/** =========================================== - (C) Mahrouss Logic - ===========================================*/ - -#ifndef __XIFF__ -#define __XIFF__ - -/** --------------------------------------------------- - - * The eXtended Information File Format. - * XIFF is used to make setup programs/audio/video files. - -------------------------------------------------------- */ - -#include - -/// @brief four-character code for XIFF. -#define kFourCCLength_XIFF 4 -#define kXIFFNameLength 255 - -#define kXIFFContainerVideo "XVFF" -#define kXIFFContainerAudio "XAFF" -#define kXIFFContainerInstaller "XNFF" -#define kXIFFContainerGeneric "XIFF" -#define kXIFFContainerBinary "XBFF" - -/*** - * @brief Generic XIFF header - * Used by XIFF based containers. - */ - -struct PACKED XiffHeader { - ByteType f_Magic[kFourCCLength_XIFF]; // XIFF string (includes \0) - DWordType f_Size; // overall size of header (XiffHeader) in bytes - DWordType f_FormatType; // format type. generic - ByteType f_SpecificMag[kFourCCLength_XIFF]; // The sub header magic - DWordType f_SpecificSize; // length of the format data - DWordType f_SpecificFormatType; // format type. generic -}; - -typedef struct XiffHeader XiffHeader; - -/// @brief XIFF metadata header, either located in forks or in file directly. -/// @author Amlal EL Mahrouss -struct PACKED XiffMetadataHeader { - ByteType f_Name[kXIFFNameLength]; - DWordType f_Flags; - DWordType f_Type; - QWordType f_Offset; - SizeType f_Size; -}; - -/// Pascal string -#define kXIFFStringMetadata4CC "strp" - -/// TrueType font -#define kXIFFFontMetadata4CC "font" - -/// UI resource -#define kXIFFResourceMetadata4CC "resx" - -#endif // ifndef __XIFF__ diff --git a/Public/Developer/System.Core/.gitkeep b/Public/Developer/System.Core/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Public/Developer/System.Core/AMD64/HCoreAssemblyRoutines.s b/Public/Developer/System.Core/AMD64/HCoreAssemblyRoutines.s deleted file mode 100644 index 58bb1260..00000000 --- a/Public/Developer/System.Core/AMD64/HCoreAssemblyRoutines.s +++ /dev/null @@ -1,24 +0,0 @@ -/** =========================================== - (C) Mahrouss Logic - ===========================================*/ - -.section .text - -.globl RtGetAppObject -.globl __assert_chk_fail - -/* @brief Process object getter */ -/* @throws: ApptError: appartement error. */ -RtGetAppObject: - mov $0x10, %rcx /* sysGetProcessObject */ - int $0x21 - - /* rax gets saved and returned. */ - ret - -__assert_chk_fail: - mov $0x11, %rcx /* sysTerminateCurrentProcess */ - int $0x21 - - ret - diff --git a/Public/Developer/System.Core/ARM64/.gitkeep b/Public/Developer/System.Core/ARM64/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Public/Developer/System.Core/Headers/Defines.h b/Public/Developer/System.Core/Headers/Defines.h deleted file mode 100644 index 56367cff..00000000 --- a/Public/Developer/System.Core/Headers/Defines.h +++ /dev/null @@ -1,207 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#ifdef CA_MUST_PASS -#undef CA_MUST_PASS -#endif - -#ifdef _DEBUG -#define CA_MUST_PASS(e) { if (!e) { DlgMsgBox("Sorry, an assertion failed.\nFile: %s\nLine: %i", __FILE__, __LINE__) __assert_chk_fail() } } -#else -#define CA_MUST_PASS(e) CA_UNREFERENCED_PARAMETER(e) -#endif - -#ifdef __cplusplus - -#define CA_EXTERN_C extern "C" - -#else - -#define CA_EXTERN_C extern - -#endif - -CA_EXTERN_C void __assert_chk_fail(void); - -#define CA_STDCALL __attribute__((stdcall)) -#define CA_CDECL __attribute__((cdecl)) -#define CA_MSCALL __attribute__((ms_abi)) - -#define PACKED __attribute__((packed)) - -#define CA_PASCAL CA_STDCALL - -typedef __UINT8_TYPE__ ByteType; -typedef __UINT16_TYPE__ WordType; -typedef __UINT32_TYPE__ DWordType; -typedef __UINT64_TYPE__ QWordType; -typedef __SIZE_TYPE__ SizeType; - -typedef char CharacterTypeUTF8; -typedef CharacterTypeUTF8* PtrCharacterType; - -typedef void* PtrVoidType; -typedef void VoidType; - -typedef __UINTPTR_TYPE__ UIntPtrType; -typedef __INTPTR_TYPE__ IntPtrType; -typedef __UINT64_TYPE__ UInt64Type; -typedef __INT64_TYPE__ Int64Type; -typedef __UINT32_TYPE__ UInt32Type; -typedef __INT32_TYPE__ Int32Type; - -typedef CharacterTypeUTF8 BooleanType; - -#define CA_COPY_DELETE(KLASS) \ - KLASS &operator=(const KLASS &) = delete; \ - KLASS(const KLASS &) = delete; - - -#define CA_COPY_DEFAULT(KLASS) \ - KLASS &operator=(const KLASS &) = default; \ - KLASS(const KLASS &) = default; - - -#define CA_MOVE_DELETE(KLASS) \ - KLASS &operator=(KLASS &&) = delete; \ - KLASS(KLASS &&) = delete; - - -#define CA_MOVE_DEFAULT(KLASS) \ - KLASS &operator=(KLASS &&) = default; \ - KLASS(KLASS &&) = default; - - -#define Yes 1 -#define No 0 - -#define CA_PTR * - -#define CA_UNREFERENCED_PARAMETER(e) ((VoidType)(e)) - -#ifdef __x86_64__ - -# define CA_FAR __far -# define CA_NEAR __near - -# define _M_AMD64 2 -#else - -# define CA_FAR -# define CA_NEAR - -#endif - -#ifdef __aarch64__ -# define _M_AARCH64 3 -#endif - -#ifdef __powerpc64__ -# define _M_PPC64 4 -#endif - -#ifdef __64x0__ -# define _M_64000 5 -#endif - -#ifdef __riscv__ -# define _M_RISCV 6 -#endif - -#define CA_STATIC static -#define CA_INLINE inline -#define CA_CONST const - -#ifdef __cplusplus -#define CA_CONSTEXPR constexpr -#else -#define CA_CONSTEXPR -#endif // __cplusplus - -enum RtProcessCall { - kCallAllocPtr = 1, - kCallFreePtr, - kCallSizePtr, - kCallCheckPtr, - kCallAllocStack, - /// @brief Open a specific handle (can be used as sel to call methods related to it.) - kCallOpenFile, - kCallCloseFile, - kCallCreateWindow, - kCallCloseWindow, - kCallCreateMenu, - kCallCloseMenu, - kCallGetArgsCount, - kCallGetArgsPtr, - /// @brief Number of process calls. - kCallsCount, -}; - -#include -#include - -#define kObjectGlobalNamespace ":\\" - -enum { - kObjectTypeGeneric, - kObjectTypeFile, - kObjectTypeDevice, - kObjectTypeNetwork, - kObjectTypeInvalid, - kObjectTypeCount = 5, -}; - -/** - * @brief GUID type, something you can also find in CFKit. - * @author Amlal El Mahrouss - */ -typedef struct GUID { - DWordType Data1; - WordType Data2; - WordType Data3; - ByteType Data4[8]; -} GUIDType, *PtrGUIDType; - -/// \brief Object handle. -/// \author Amlal El Mahrouss -typedef struct Object { - CharacterTypeUTF8 Name[255]; - DWordType Kind; - DWordType Flags; - - VoidType(*Release)(struct Object* Self); - IntPtrType(*Invoke)(struct Object* Self, DWordType Sel, ...); - VoidType(*Query)(struct Object* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); -} *ObjectRef; - -#ifdef __cplusplus - -#define object_cast reinterpret_cast - -template -using StrType = CharacterTypeUTF8[N]; - -#else - -#define object_cast (ObjectRef) - -#endif // ifdef C++ - -CA_EXTERN_C ObjectRef RtGetAppObject(VoidType); -CA_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType); -CA_EXTERN_C CharacterTypeUTF8* RtGetAppArgumentsPtr(VoidType); - -CA_EXTERN_C ObjectRef kApplicationObject; - -typedef CharacterTypeUTF8 Str255Type[255]; - -#define True 1 -#define False 0 -#define Bool BooleanType - -#define NULL ((PtrVoidType)0) diff --git a/Public/Developer/System.Core/Headers/Dialog.h b/Public/Developer/System.Core/Headers/Dialog.h deleted file mode 100644 index 9d4521cf..00000000 --- a/Public/Developer/System.Core/Headers/Dialog.h +++ /dev/null @@ -1,16 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -/// @brief Shows an message box with a formatting. -/// @param title the message box title -/// @param format the format -/// @param va_list the va args, that goes along with it. -/// @return void this function returns nothing. -CA_EXTERN_C VoidType DlgMsgBox(CharacterTypeUTF8* title, CharacterTypeUTF8* format, ...); diff --git a/Public/Developer/System.Core/Headers/File.h b/Public/Developer/System.Core/Headers/File.h deleted file mode 100644 index 13bc7a00..00000000 --- a/Public/Developer/System.Core/Headers/File.h +++ /dev/null @@ -1,44 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -/// @brief Filesystem wrapper. - -typedef QWordTyp FSRef; - -/// @brief Opens a new file. -/// @param path where to find it. -/// @param r the restrict (rw, rwe, r+, w+, r, w) -/// @return -CA_EXTERN_C FSRef FsOpenFile(const CharacterTypeUTF8* path, const CharacterTypeUTF8* r); - -/// @brief Closes the file and flushes it to the said file. -/// @param refFs the filesystem reference. -/// @return -CA_EXTERN_C VoidType FsCloseFile(FSRef refFs); - -typedef QWordTyp FSForkRef; - -/// @brief A fork information header. -typedef struct _Fork { - PtrVoidType forkData; - SizeType forkSize; - Int32Type forkFlags; - Int32Type forkKind; - CharacterTypeUTF8 forkName[256]; -} ForkType; - -/// @brief Gets the fork inside a file. -/// @param refFs the filesystem ref -/// @param forkName the fork's name -/// @return the fork data. -CA_EXTERN_C FSForkRef FsGetFork(FSRef refFs, const CharacterTypeUTF8* forkName); - -#define FsGetDataFork(refFs) FsGetFork(refFs, "data") -#define FsGetRsrcFork(refFs) FsGetFork(refFs, "rsrc") diff --git a/Public/Developer/System.Core/Headers/Heap.h b/Public/Developer/System.Core/Headers/Heap.h deleted file mode 100644 index 9f3215db..00000000 --- a/Public/Developer/System.Core/Headers/Heap.h +++ /dev/null @@ -1,38 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -#define kAllocationTypes 2 - -enum RtAllocationKind { - kStandardAllocation = 0xC, - kArrayAllocation = 0xD, -}; - -/// @brief Allocates a new pointer from process pool. -/// @param sz the size -/// @param flags the allocation flags. -/// @return -CA_EXTERN_C PtrVoidType RtAllocateProcessPtr(QWordType sz, - DWordType flags); - -/// @brief Check if the pointer exists. -/// @param ptr the pointer to free. -/// @return -CA_EXTERN_C BooleanType RtProcessPtrExists(PtrVoidType ptr); - -/// @brief Gets the size of the process' pointer. -/// @param ptr the pointer to free. -/// @return -CA_EXTERN_C QWordType RtProcessPtrSize(PtrVoidType ptr); - -/// @brief Frees the process pointer. -/// @param ptr the pointer to free. -/// @return -CA_EXTERN_C VoidType RtFreeProcessPtr(PtrVoidType ptr); diff --git a/Public/Developer/System.Core/Headers/Hint.h b/Public/Developer/System.Core/Headers/Hint.h deleted file mode 100644 index 86faf455..00000000 --- a/Public/Developer/System.Core/Headers/Hint.h +++ /dev/null @@ -1,18 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#define _Input -#define _Output - -#define _Optional - -#define _StrictCheckInput -#define _StrictCheckOutput - -#define _InOut -#define _StrictInOut diff --git a/Public/Developer/System.Core/Headers/Thread.h b/Public/Developer/System.Core/Headers/Thread.h deleted file mode 100644 index 7d2bfe3c..00000000 --- a/Public/Developer/System.Core/Headers/Thread.h +++ /dev/null @@ -1,43 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -// -// Created by Amlal on 3/18/24 -// - -#ifndef __THREAD__ -#define __THREAD__ - -#include - -#define kThreadErrorExit -33 - -/// @brief Thread Information Block, which holds information about the running -/// thread. -typedef QWordType ThreadRef; - -/// @brief Main application thread. -CA_EXTERN_C ThreadRef kMainThread; - -typedef VoidType(*ThreadEntrypointKind)(VoidType); - -/// @brief Creates a new thread, and runs the code. -/// @param threadName the thread's name. -/// @param threadStart where to start. -/// @return -CA_EXTERN_C ThreadRef TmCreateThread(const CharacterTypeUTF8* threadName, ThreadEntrypointKind threadStart); - -/// @brief Dispoes the thread, and exits with code kThreadErrorExit -/// @param ref the thread reference. -/// @return nothing. -CA_EXTERN_C VoidType TmDisposeThread(ThreadRef ref); - -/// @brief Waits for the thread to complete. -/// @param ref the thread reference. -/// @return nothing. -CA_EXTERN_C VoidType TmWaitForCompletion(ThreadRef ref); - -#endif // __THREAD__ diff --git a/Public/Developer/System.Core/Headers/TrueType.h b/Public/Developer/System.Core/Headers/TrueType.h deleted file mode 100644 index 2e8f4142..00000000 --- a/Public/Developer/System.Core/Headers/TrueType.h +++ /dev/null @@ -1,32 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -/************************************************************* - * - * File: TrueType.hxx - * Purpose: TrueType font implementation for NewOS. - * Date: 3/26/24 - * - * Copyright Mahrouss Logic, all rights reserved. - * - *************************************************************/ - -typedef QWordType TTFFontRef; - -/// @brief Loads a new font into app's memory. -/// @param name -/// @return -CA_EXTERN_C TTFFontRef FnCreateFont(const CharacterTypeUTF8* name); - -/// @brief Dispose an allocated font. -/// @param fon -/// @return -CA_EXTERN_C VoidType FnDisposeFont(TTFFontRef fon); - diff --git a/Public/Developer/System.Core/Headers/Window.h b/Public/Developer/System.Core/Headers/Window.h deleted file mode 100644 index 846d5cff..00000000 --- a/Public/Developer/System.Core/Headers/Window.h +++ /dev/null @@ -1,153 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -/************************************************************* - * - * File: Window.hxx - * Purpose: Window Manager API for NewOS. - * Date: 3/26/24 - * - * Copyright Mahrouss Logic, all rights reserved. - * - *************************************************************/ - -struct _WmPoint; -struct _WindowPort; - -#ifdef __SINGLE_PRECISION__ -typedef float PositionType; -#else -typedef double PositionType; -#endif - -typedef QWordType DCRef; - -/// @brief A point, can represent the size, position of a window. -typedef struct _WmPoint { - PositionType X, Y; -} WmPoint; - -/// @brief Window port type, can be used to control the window. -typedef struct _WindowPort { - WordType windowPort; - WordType windowKind; - BooleanType windowVisible; - BooleanType windowMaximized; - BooleanType windowMinimized; - BooleanType windowMoving; - BooleanType windowDisableClose; - BooleanType windowDisableMinimize; - WmPoint windowPosition; - WmPoint windowSize; - BooleanType windowInvalidate; - DWordType windowClearColor; - struct _WindowPort* menuPort; - struct _WindowPort* parentPort; -} WindowPort; - -typedef struct _ControlPort { - WordType controlPort; - WordType controlKind; - BooleanType controlVisible; - BooleanType controlMoving; - WmPoint controlPosition; - WindowPort* parentPort; -} ControlPort; - -typedef UInt32Type ColorRef; - -/***********************************************************************************/ -/// Color utils. -/***********************************************************************************/ - -CA_EXTERN_C const ColorRef kRgbRed; -CA_EXTERN_C const ColorRef kRgbGreen; -CA_EXTERN_C const ColorRef kRgbBlue; -CA_EXTERN_C const ColorRef kRgbBlack; -CA_EXTERN_C const ColorRef kRgbWhite; - -/***********************************************************************************/ -/// Color macro. -/***********************************************************************************/ - -#define WmMakeColorRef(R, G, B) (ColorRef)(0x##R##G##B) - -#define kControlKindWindow 0 -#define kControlKindDialog 1 -#define kControlKindMenu 2 -#define kControlKindButton 3 -#define kControlKindLabel 4 -#define kControlKindDropdown 5 -#define kControlKindIcon 6 -#define kControlKindRadio 7 -#define kControlKindCheck 7 - -/// @brief Creates a new control -/// @param id the control rsrc fork. -/// @return -CA_EXTERN_C ControlPort* WmCreateControl(DWordType id); - -/// @brief Releases the control -/// @param id the control ref. -/// @return -CA_EXTERN_C VoidType WmReleaseControl(ControlPort* id); - -/// @brief Moves a control inside a ControlPort. -/// @param id the control ref. -/// @param where where to move at. -/// @return -CA_EXTERN_C Int32Type WmSetControlPosition(ControlPort* id, WmPoint where); - -/// @brief Enable control. -/// @param id -/// @param enabled -/// @return -CA_EXTERN_C Int32Type WmSetControlEnabled(ControlPort* id, BooleanType enabled); - -/// @brief Make control visible. -/// @param id -/// @param visible -/// @return -CA_EXTERN_C Int32Type WmMakeControlVisible(ControlPort* id, BooleanType visible); - -/// @brief Creates a new window. -/// @param name the window name -/// @param rsrcId the window fork rsrc id. -/// @return the window graphics port. -CA_EXTERN_C WindowPort* WmCreateWindow(const CharacterTypeUTF8* name, const DWordType rsrcId); - -/// @brief Creates a new menu -/// @param name the menu's name -/// @param rsrcId the menu fork rsrc id. -/// @return the menu graphics port. -CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* name, const DWordType rsrcId); - -/// @brief Releases the window. -/// @param port the window port. -/// @return void -CA_EXTERN_C VoidType WmReleaseWindow(WindowPort* port); - -/// @brief Releases the menu -/// @param port the menu port. -/// @return void -CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* port); - -/// @brief Moves a window on the desktop. (menu arent movable, will return kErrIncompatible is menu is provided.) -/// @param id the gfx port. -/// @param where to move. -/// @return error code. -CA_EXTERN_C Int32Type WmMoveWindow(WindowPort* id, WmPoint where); - -enum { - kWmErrIncompatible = 0x74, - kWmErrOutOfMemory, - kWmErrInvalidArg, - kWmErrNotImplemented, -}; diff --git a/Public/Developer/System.Core/Makefile b/Public/Developer/System.Core/Makefile deleted file mode 100644 index b9a0a663..00000000 --- a/Public/Developer/System.Core/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -################################################## -# (C) Mahrouss Logic, all rights reserved. -# This is the SystemLib Makefile. -################################################## - -CC=x86_64-w64-mingw32-gcc -AR=x86_64-w64-mingw32-ar -ARFLAGS=-rcs -CCINC=-I../ -CCFLAGS=-D__SINGLE_PRECISION__ -nostdlib -std=c17 -ffreestanding -Xlinker --subsystem=17 -shared -OUTPUT=SystemLib.lib - -.PHONY: all -all: build-core-amd64 - @echo "[SystemLib.lib] Build done." - -.PHONY: build-core-amd64 -build-core-amd64: - $(CC) $(CCINC) $(CCFLAGS) $(wildcard Sources/*.c) $(wildcard AMD64/*.s) -o $(OUTPUT) - -.PHONY: clean -clean: - rm -f $(wildcard *.o) diff --git a/Public/Developer/System.Core/RISCV/.gitkeep b/Public/Developer/System.Core/RISCV/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Public/Developer/System.Core/ReadMe.md b/Public/Developer/System.Core/ReadMe.md deleted file mode 100644 index 3867dd3d..00000000 --- a/Public/Developer/System.Core/ReadMe.md +++ /dev/null @@ -1,8 +0,0 @@ -# System.Core -## Core System API. - -Currently contains: -- Heap API. -- File API. -- Data types. -- Threading API. \ No newline at end of file diff --git a/Public/Developer/System.Core/Sources/App.c b/Public/Developer/System.Core/Sources/App.c deleted file mode 100644 index 0bd7fd03..00000000 --- a/Public/Developer/System.Core/Sources/App.c +++ /dev/null @@ -1,20 +0,0 @@ -/** =========================================== - (C) Mahrouss Logic - ===========================================*/ - -#include - -/// @brief Gets the app arguments count. -/// @param -/// @return -CA_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) { - return kApplicationObject->Invoke(kApplicationObject, kCallGetArgsCount); -} - -/// @brief Gets the app arguments pointer. -/// @param -/// @return -CA_EXTERN_C CharacterTypeUTF8* RtGetAppArgumentsPtr(VoidType) { - return (CharacterTypeUTF8*)kApplicationObject->Invoke(kApplicationObject, - kCallGetArgsPtr); -} \ No newline at end of file diff --git a/Public/Developer/System.Core/Sources/Heap.c b/Public/Developer/System.Core/Sources/Heap.c deleted file mode 100644 index db4a16bf..00000000 --- a/Public/Developer/System.Core/Sources/Heap.c +++ /dev/null @@ -1,42 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include - -/// @brief Allocate from the user's heap. -/// @param sz size of object. -/// @param flags flags. -/// @return -CA_EXTERN_C PtrVoidType RtAllocateProcessPtr(QWordType sz, - DWordType flags) { - CA_MUST_PASS(sz); - CA_MUST_PASS(flags); - - return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, kCallAllocPtr, sz, flags); -} - -/// @brief Free pointer from the user's heap. -/// @param ptr the pointer to free. -CA_EXTERN_C VoidType RtFreeProcessPtr(PtrVoidType ptr) { - CA_MUST_PASS(ptr); - CA_UNREFERENCED_PARAMETER(kApplicationObject->Invoke(kApplicationObject, kCallFreePtr, ptr)); -} - -/// @brief Get pointer size. -/// @param ptr the pointer to find. -/// @return the size. -CA_EXTERN_C QWordType RtProcessPtrSize(PtrVoidType ptr) { - CA_MUST_PASS(ptr); - return kApplicationObject->Invoke(kApplicationObject, kCallSizePtr, ptr); -} - -/// @brief Check if the pointer exists. -/// @param ptr the pointer to check. -/// @return if it exists -CA_EXTERN_C BooleanType RtProcessPtrExists(PtrVoidType ptr) { - CA_MUST_PASS(ptr); - return kApplicationObject->Invoke(kApplicationObject, kCallCheckPtr, ptr); -} diff --git a/Public/Developer/System.Core/Sources/Start.c b/Public/Developer/System.Core/Sources/Start.c deleted file mode 100644 index 24d41a1e..00000000 --- a/Public/Developer/System.Core/Sources/Start.c +++ /dev/null @@ -1,15 +0,0 @@ -/** =========================================== - (C) Mahrouss Logic - ===========================================*/ - -#include - -/// @brief Main Application object, retrieved from __start symbol. -CA_EXTERN_C ObjectRef kApplicationObject = NULL; - -/// @brief Inits the library. -/// @return if it was succesful or not. -CA_EXTERN_C VoidType __start(VoidType) { - kApplicationObject = RtGetAppObject(); - CA_MUST_PASS(kApplicationObject); -} diff --git a/Public/Developer/System.Core/Sources/Window.c b/Public/Developer/System.Core/Sources/Window.c deleted file mode 100644 index b68c1afb..00000000 --- a/Public/Developer/System.Core/Sources/Window.c +++ /dev/null @@ -1,70 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include - -/// invalid resource handle, they always start from 1. -#define kInvalidRsrc 0 - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C WindowPort* WmCreateWindow(const CharacterTypeUTF8* name, - const DWordType rsrcId) { - CA_MUST_PASS(name); - CA_MUST_PASS(rsrcId != kInvalidRsrc); - - return (WindowPort*)kApplicationObject->Invoke( - kApplicationObject, kCallCreateWindow, name, rsrcId); -} - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C VoidType WmReleaseWindow(WindowPort* winPort) { - CA_MUST_PASS(winPort); - - kApplicationObject->Invoke(kApplicationObject, kCallCloseWindow, winPort); -} - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* name, - const DWordType rsrcId) { - CA_MUST_PASS(name); - CA_MUST_PASS(rsrcId != kInvalidRsrc); - - return (WindowPort*)kApplicationObject->Invoke(kApplicationObject, - kCallCreateMenu, name, rsrcId); -} - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* winPort) { - CA_MUST_PASS(winPort); - - kApplicationObject->Invoke(kApplicationObject, kCallCloseMenu, winPort); -} - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C Int32Type WmMoveWindow(WindowPort* id, WmPoint where) { - if (!id) { - return kWmErrInvalidArg; - } - - id->windowPosition.X = where.X; - id->windowPosition.Y = where.Y; - id->windowMoving = True; - - return 0; -} - -/// Colors! - -CA_EXTERN_C const ColorRef kRgbRed = 0x000000FF; -CA_EXTERN_C const ColorRef kRgbGreen = 0x0000FF00; -CA_EXTERN_C const ColorRef kRgbBlue = 0x00FF0000; -CA_EXTERN_C const ColorRef kRgbBlack = 0x00000000; -CA_EXTERN_C const ColorRef kRgbWhite = 0xFFFFFFFF; diff --git a/Public/Developer/System.Core/compile_flags.txt b/Public/Developer/System.Core/compile_flags.txt deleted file mode 100644 index 6e721e73..00000000 --- a/Public/Developer/System.Core/compile_flags.txt +++ /dev/null @@ -1,4 +0,0 @@ --I./ --I../ --I../../../Private --std=c++20 diff --git a/Public/Developer/System.Cxx/.gitkeep b/Public/Developer/System.Cxx/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Public/Developer/System.Cxx/Sources/New+Delete.cxx b/Public/Developer/System.Cxx/Sources/New+Delete.cxx deleted file mode 100644 index b54b5ea8..00000000 --- a/Public/Developer/System.Cxx/Sources/New+Delete.cxx +++ /dev/null @@ -1,27 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include - -typedef SizeType size_t; - -void* operator new[](size_t sz) { - if (sz == 0) ++sz; - - return RtAllocateProcessPtr(sz, kStandardAllocation); -} - -void* operator new(size_t sz) { - if (sz == 0) ++sz; - - return RtAllocateProcessPtr(sz, kArrayAllocation); -} - -void operator delete[](void* ptr) { - if (ptr == nullptr) return; - - RtFreeProcessPtr(ptr); -} \ No newline at end of file diff --git a/Public/Developer/System.Driver/.gitkeep b/Public/Developer/System.Driver/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Public/Developer/SystemLib/.gitkeep b/Public/Developer/SystemLib/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Public/Developer/SystemLib/AMD64/HCoreAssemblyRoutines.s b/Public/Developer/SystemLib/AMD64/HCoreAssemblyRoutines.s new file mode 100644 index 00000000..58bb1260 --- /dev/null +++ b/Public/Developer/SystemLib/AMD64/HCoreAssemblyRoutines.s @@ -0,0 +1,24 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +.section .text + +.globl RtGetAppObject +.globl __assert_chk_fail + +/* @brief Process object getter */ +/* @throws: ApptError: appartement error. */ +RtGetAppObject: + mov $0x10, %rcx /* sysGetProcessObject */ + int $0x21 + + /* rax gets saved and returned. */ + ret + +__assert_chk_fail: + mov $0x11, %rcx /* sysTerminateCurrentProcess */ + int $0x21 + + ret + diff --git a/Public/Developer/SystemLib/ARM64/.gitkeep b/Public/Developer/SystemLib/ARM64/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Public/Developer/SystemLib/Headers/Defines.h b/Public/Developer/SystemLib/Headers/Defines.h new file mode 100644 index 00000000..c4cc552b --- /dev/null +++ b/Public/Developer/SystemLib/Headers/Defines.h @@ -0,0 +1,196 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#ifdef CA_MUST_PASS +#undef CA_MUST_PASS +#endif + +#ifdef _DEBUG +#define CA_MUST_PASS(e) { if (!e) { DlgMsgBox("Sorry, an assertion failed.\nFile: %s\nLine: %i", __FILE__, __LINE__) __assert_chk_fail() } } +#else +#define CA_MUST_PASS(e) CA_UNREFERENCED_PARAMETER(e) +#endif + +#ifdef __cplusplus + +#define CA_EXTERN_C extern "C" + +#else + +#define CA_EXTERN_C extern + +#endif + +CA_EXTERN_C void __assert_chk_fail(void); + +#define CA_STDCALL __attribute__((stdcall)) +#define CA_CDECL __attribute__((cdecl)) +#define CA_MSCALL __attribute__((ms_abi)) + +#define PACKED __attribute__((packed)) + +#define CA_PASCAL CA_STDCALL + +typedef __UINT8_TYPE__ ByteType; +typedef __UINT16_TYPE__ WordType; +typedef __UINT32_TYPE__ DWordType; +typedef __UINT64_TYPE__ QWordType; +typedef __SIZE_TYPE__ SizeType; + +typedef char CharacterTypeUTF8; +typedef CharacterTypeUTF8* PtrCharacterType; + +typedef void* PtrVoidType; +typedef void VoidType; + +typedef __UINTPTR_TYPE__ UIntPtrType; +typedef __INTPTR_TYPE__ IntPtrType; +typedef __UINT64_TYPE__ UInt64Type; +typedef __INT64_TYPE__ Int64Type; +typedef __UINT32_TYPE__ UInt32Type; +typedef __INT32_TYPE__ Int32Type; + +typedef CharacterTypeUTF8 BooleanType; + +#define CA_COPY_DELETE(KLASS) \ + KLASS &operator=(const KLASS &) = delete; \ + KLASS(const KLASS &) = delete; + + +#define CA_COPY_DEFAULT(KLASS) \ + KLASS &operator=(const KLASS &) = default; \ + KLASS(const KLASS &) = default; + + +#define CA_MOVE_DELETE(KLASS) \ + KLASS &operator=(KLASS &&) = delete; \ + KLASS(KLASS &&) = delete; + + +#define CA_MOVE_DEFAULT(KLASS) \ + KLASS &operator=(KLASS &&) = default; \ + KLASS(KLASS &&) = default; + + +#define Yes 1 +#define No 0 + +#define CA_PTR * + +#define CA_UNREFERENCED_PARAMETER(e) ((VoidType)(e)) + +#ifdef __x86_64__ + +# define CA_FAR __far +# define CA_NEAR __near + +# define _M_AMD64 2 +#else + +# define CA_FAR +# define CA_NEAR + +#endif + +#ifdef __aarch64__ +# define _M_AARCH64 3 +#endif + +#ifdef __powerpc64__ +# define _M_PPC64 4 +#endif + +#ifdef __64x0__ +# define _M_64000 5 +#endif + +#ifdef __riscv__ +# define _M_RISCV 6 +#endif + +#define CA_STATIC static +#define CA_INLINE inline +#define CA_CONST const + +#ifdef __cplusplus +#define CA_CONSTEXPR constexpr +#else +#define CA_CONSTEXPR +#endif // __cplusplus + +enum RtProcessCall { + kCallAllocPtr = 1, + kCallFreePtr, + kCallSizePtr, + kCallCheckPtr, + kCallAllocStack, + /// @brief Open a specific handle (can be used as sel to call methods related to it.) + kCallOpenFile, + kCallCloseFile, + kCallCreateWindow, + kCallCloseWindow, + kCallCreateMenu, + kCallCloseMenu, + kCallGetArgsCount, + kCallGetArgsPtr, + /// @brief Number of process calls. + kCallsCount, +}; + +#include +#include + +/** + * @brief GUID type, something you can also find in CFKit. + * @author Amlal El Mahrouss + */ +typedef struct GUID { + DWordType Data1; + WordType Data2; + WordType Data3; + ByteType Data4[8]; +} GUIDType, *PtrGUIDType; + +/// \brief Application Interface. +/// \author Amlal El Mahrouss +typedef struct Application { + VoidType(*Release)(struct Application* Self, DWordType ExitCode); + IntPtrType(*Invoke)(struct Application* Self, DWordType Sel, ...); + VoidType(*Query)(struct Application* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); +} Application, *ApplicationRef; + +#ifdef __cplusplus + +#define object_cast reinterpret_cast + +template +using StrType = CharacterTypeUTF8[N]; + +#else + +#define object_cast (ApplicationRef) + +#endif // ifdef C++ + +CA_EXTERN_C ApplicationRef RtGetAppObject(VoidType); +CA_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType); +CA_EXTERN_C CharacterTypeUTF8* RtGetAppArgumentsPtr(VoidType); + +CA_EXTERN_C ApplicationRef kSharedApplication; + +typedef CharacterTypeUTF8 StrType255[255]; + +#define True 1 +#define False 0 +#define Bool BooleanType + +#define NullPtr ((PtrVoidType)0) + +#ifndef kInvalidRef +#define kInvalidRef 0 +#endif diff --git a/Public/Developer/SystemLib/Headers/Dialog.h b/Public/Developer/SystemLib/Headers/Dialog.h new file mode 100644 index 00000000..d3e8df44 --- /dev/null +++ b/Public/Developer/SystemLib/Headers/Dialog.h @@ -0,0 +1,16 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +/// @brief Shows an message box with a formatting. +/// @param title the message box title +/// @param format the format +/// @param va_list the va args, that goes along with it. +/// @return void this function returns nothing. +CA_EXTERN_C VoidType DlgMsgBox(CharacterTypeUTF8* title, CharacterTypeUTF8* format, ...); diff --git a/Public/Developer/SystemLib/Headers/File.h b/Public/Developer/SystemLib/Headers/File.h new file mode 100644 index 00000000..0bce05f9 --- /dev/null +++ b/Public/Developer/SystemLib/Headers/File.h @@ -0,0 +1,44 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +/// @brief Filesystem wrapper. + +typedef QWordTyp FSRef; + +/// @brief Opens a new file. +/// @param path where to find it. +/// @param r the restrict (rw, rwe, r+, w+, r, w) +/// @return +CA_EXTERN_C FSRef FsOpenFile(const CharacterTypeUTF8* path, const CharacterTypeUTF8* r); + +/// @brief Closes the file and flushes it to the said file. +/// @param refFs the filesystem reference. +/// @return +CA_EXTERN_C VoidType FsCloseFile(FSRef refFs); + +typedef QWordTyp FSForkRef; + +/// @brief A fork information header. +typedef struct _Fork { + PtrVoidType forkData; + SizeType forkSize; + Int32Type forkFlags; + Int32Type forkKind; + CharacterTypeUTF8 forkName[256]; +} ForkType; + +/// @brief Gets the fork inside a file. +/// @param refFs the filesystem ref +/// @param forkName the fork's name +/// @return the fork data. +CA_EXTERN_C FSForkRef FsGetFork(FSRef refFs, const CharacterTypeUTF8* forkName); + +#define FsGetDataFork(refFs) FsGetFork(refFs, "data") +#define FsGetRsrcFork(refFs) FsGetFork(refFs, "rsrc") diff --git a/Public/Developer/SystemLib/Headers/Heap.h b/Public/Developer/SystemLib/Headers/Heap.h new file mode 100644 index 00000000..2dc13b0f --- /dev/null +++ b/Public/Developer/SystemLib/Headers/Heap.h @@ -0,0 +1,38 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +#define kAllocationTypes 2 + +enum RtAllocationKind { + kStandardAllocation = 0xC, + kArrayAllocation = 0xD, +}; + +/// @brief Allocates a new pointer from process pool. +/// @param sz the size +/// @param flags the allocation flags. +/// @return +CA_EXTERN_C PtrVoidType RtAllocateProcessPtr(QWordType sz, + DWordType flags); + +/// @brief Check if the pointer exists. +/// @param ptr the pointer to free. +/// @return +CA_EXTERN_C BooleanType RtProcessPtrExists(PtrVoidType ptr); + +/// @brief Gets the size of the process' pointer. +/// @param ptr the pointer to free. +/// @return +CA_EXTERN_C QWordType RtProcessPtrSize(PtrVoidType ptr); + +/// @brief Frees the process pointer. +/// @param ptr the pointer to free. +/// @return +CA_EXTERN_C VoidType RtFreeProcessPtr(PtrVoidType ptr); diff --git a/Public/Developer/SystemLib/Headers/Hint.h b/Public/Developer/SystemLib/Headers/Hint.h new file mode 100644 index 00000000..86faf455 --- /dev/null +++ b/Public/Developer/SystemLib/Headers/Hint.h @@ -0,0 +1,18 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#define _Input +#define _Output + +#define _Optional + +#define _StrictCheckInput +#define _StrictCheckOutput + +#define _InOut +#define _StrictInOut diff --git a/Public/Developer/SystemLib/Headers/Thread.h b/Public/Developer/SystemLib/Headers/Thread.h new file mode 100644 index 00000000..4a54d841 --- /dev/null +++ b/Public/Developer/SystemLib/Headers/Thread.h @@ -0,0 +1,43 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +// +// Created by Amlal on 3/18/24 +// + +#ifndef __THREAD__ +#define __THREAD__ + +#include + +#define kThreadErrorExit -33 + +/// @brief Thread Information Block, which holds information about the running +/// thread. +typedef QWordType ThreadRef; + +/// @brief Main application thread. +CA_EXTERN_C ThreadRef kMainThread; + +typedef VoidType(*ThreadEntrypointKind)(VoidType); + +/// @brief Creates a new thread, and runs the code. +/// @param threadName the thread's name. +/// @param threadStart where to start. +/// @return +CA_EXTERN_C ThreadRef TmCreateThread(const CharacterTypeUTF8* threadName, ThreadEntrypointKind threadStart); + +/// @brief Dispoes the thread, and exits with code kThreadErrorExit +/// @param ref the thread reference. +/// @return nothing. +CA_EXTERN_C VoidType TmDisposeThread(ThreadRef ref); + +/// @brief Waits for the thread to complete. +/// @param ref the thread reference. +/// @return nothing. +CA_EXTERN_C VoidType TmWaitForCompletion(ThreadRef ref); + +#endif // __THREAD__ diff --git a/Public/Developer/SystemLib/Headers/TrueType.h b/Public/Developer/SystemLib/Headers/TrueType.h new file mode 100644 index 00000000..0636bf61 --- /dev/null +++ b/Public/Developer/SystemLib/Headers/TrueType.h @@ -0,0 +1,31 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +/************************************************************* + * + * File: TrueType.hxx + * Purpose: TrueType font implementation for NewOS. + * Date: 3/26/24 + * + * Copyright Mahrouss Logic, all rights reserved. + * + *************************************************************/ + +typedef QWordType TTFFontRef; + +/// @brief Loads a new font into app's memory. +/// @param name +/// @return +CA_EXTERN_C TTFFontRef FnCreateFont(const CharacterTypeUTF8* name); + +/// @brief Dispose an allocated font. +/// @param fon +/// @return +CA_EXTERN_C VoidType FnDisposeFont(TTFFontRef fon); diff --git a/Public/Developer/SystemLib/Headers/Window.h b/Public/Developer/SystemLib/Headers/Window.h new file mode 100644 index 00000000..4d526782 --- /dev/null +++ b/Public/Developer/SystemLib/Headers/Window.h @@ -0,0 +1,153 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +/************************************************************* + * + * File: Window.hxx + * Purpose: Window Manager API for NewOS. + * Date: 3/26/24 + * + * Copyright Mahrouss Logic, all rights reserved. + * + *************************************************************/ + +struct _WmPoint; +struct _WindowPort; + +#ifdef __SINGLE_PRECISION__ +typedef float PositionType; +#else +typedef double PositionType; +#endif + +typedef QWordType DCRef; + +/// @brief A point, can represent the size, position of a window. +typedef struct _WmPoint { + PositionType X, Y; +} WmPoint; + +/// @brief Window port type, can be used to control the window. +typedef struct _WindowPort { + WordType windowPort; + WordType windowKind; + BooleanType windowVisible; + BooleanType windowMaximized; + BooleanType windowMinimized; + BooleanType windowMoving; + BooleanType windowDisableClose; + BooleanType windowDisableMinimize; + WmPoint windowPosition; + WmPoint windowSize; + BooleanType windowInvalidate; + DWordType windowClearColor; + struct _WindowPort* menuPort; + struct _WindowPort* parentPort; +} WindowPort; + +typedef struct _ControlPort { + WordType controlPort; + WordType controlKind; + BooleanType controlVisible; + BooleanType controlMoving; + WmPoint controlPosition; + WindowPort* parentPort; +} ControlPort; + +typedef UInt32Type ColorRef; + +/***********************************************************************************/ +/// Color utils. +/***********************************************************************************/ + +CA_EXTERN_C const ColorRef kRgbRed; +CA_EXTERN_C const ColorRef kRgbGreen; +CA_EXTERN_C const ColorRef kRgbBlue; +CA_EXTERN_C const ColorRef kRgbBlack; +CA_EXTERN_C const ColorRef kRgbWhite; + +/***********************************************************************************/ +/// Color macro. +/***********************************************************************************/ + +#define WmMakeColorRef(R, G, B) (ColorRef)(0x##R##G##B) + +#define kControlKindWindow 0 +#define kControlKindDialog 1 +#define kControlKindMenu 2 +#define kControlKindButton 3 +#define kControlKindLabel 4 +#define kControlKindDropdown 5 +#define kControlKindIcon 6 +#define kControlKindRadio 7 +#define kControlKindCheck 7 + +/// @brief Creates a new control +/// @param id the control rsrc fork. +/// @return +CA_EXTERN_C ControlPort* WmCreateControl(DWordType id); + +/// @brief Releases the control +/// @param id the control ref. +/// @return +CA_EXTERN_C VoidType WmReleaseControl(ControlPort* id); + +/// @brief Moves a control inside a ControlPort. +/// @param id the control ref. +/// @param where where to move at. +/// @return +CA_EXTERN_C Int32Type WmSetControlPosition(ControlPort* id, WmPoint where); + +/// @brief Enable control. +/// @param id +/// @param enabled +/// @return +CA_EXTERN_C Int32Type WmSetControlEnabled(ControlPort* id, BooleanType enabled); + +/// @brief Make control visible. +/// @param id +/// @param visible +/// @return +CA_EXTERN_C Int32Type WmMakeControlVisible(ControlPort* id, BooleanType visible); + +/// @brief Creates a new window. +/// @param name the window name +/// @param rsrcId the window fork rsrc id. +/// @return the window graphics port. +CA_EXTERN_C WindowPort* WmCreateWindow(const CharacterTypeUTF8* name, const DWordType rsrcId); + +/// @brief Creates a new menu +/// @param name the menu's name +/// @param rsrcId the menu fork rsrc id. +/// @return the menu graphics port. +CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* name, const DWordType rsrcId); + +/// @brief Releases the window. +/// @param port the window port. +/// @return void +CA_EXTERN_C VoidType WmReleaseWindow(WindowPort* port); + +/// @brief Releases the menu +/// @param port the menu port. +/// @return void +CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* port); + +/// @brief Moves a window on the desktop. (menu arent movable, will return kErrIncompatible is menu is provided.) +/// @param id the gfx port. +/// @param where to move. +/// @return error code. +CA_EXTERN_C Int32Type WmMoveWindow(WindowPort* id, WmPoint where); + +enum { + kWmErrIncompatible = 0x74, + kWmErrOutOfMemory, + kWmErrInvalidArg, + kWmErrNotImplemented, +}; diff --git a/Public/Developer/SystemLib/Makefile b/Public/Developer/SystemLib/Makefile new file mode 100644 index 00000000..21b21ad9 --- /dev/null +++ b/Public/Developer/SystemLib/Makefile @@ -0,0 +1,23 @@ +################################################## +# (C) Mahrouss Logic, all rights reserved. +# This is the SystemLib Makefile. +################################################## + +CC=x86_64-w64-mingw32-gcc +AR=x86_64-w64-mingw32-ar +ARFLAGS=-rcs +CCINC=-I./ +CCFLAGS=-D__SINGLE_PRECISION__ -nostdlib -std=c17 -ffreestanding -Xlinker --subsystem=17 -shared +OUTPUT=SystemLib.lib + +.PHONY: all +all: build-core-amd64 + @echo "[SystemLib.lib] Build done." + +.PHONY: build-core-amd64 +build-core-amd64: + $(CC) $(CCINC) $(CCFLAGS) $(wildcard Sources/*.c) $(wildcard AMD64/*.s) -o $(OUTPUT) + +.PHONY: clean +clean: + rm -f $(wildcard *.o) diff --git a/Public/Developer/SystemLib/RISCV/.gitkeep b/Public/Developer/SystemLib/RISCV/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Public/Developer/SystemLib/ReadMe.md b/Public/Developer/SystemLib/ReadMe.md new file mode 100644 index 00000000..ff89e847 --- /dev/null +++ b/Public/Developer/SystemLib/ReadMe.md @@ -0,0 +1,14 @@ +# SystemLib +## System API. + +Currently contains: +- Heap API. +- File API. +- Window Manager API. +- Dialogs API. +- Data types. +- Threading API. + +Needs: +- Device API +- Drive API. \ No newline at end of file diff --git a/Public/Developer/SystemLib/Sources/Application.c b/Public/Developer/SystemLib/Sources/Application.c new file mode 100644 index 00000000..d7a83d3e --- /dev/null +++ b/Public/Developer/SystemLib/Sources/Application.c @@ -0,0 +1,25 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include + +/// @brief Main Application object, retrieved from the RtGetAppObject symbol. +ApplicationRef kSharedApplication = NullPtr; + +/// @brief Gets the app arguments count. +/// @param void no arguments. +/// @return +CA_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) { + return kSharedApplication->Invoke(kSharedApplication, kCallGetArgsCount); +} + +/// @brief Gets the app arguments pointer. +/// @param void no arguments. +/// @return +CA_EXTERN_C CharacterTypeUTF8* RtGetAppArgumentsPtr(VoidType) { + return (CharacterTypeUTF8*)kSharedApplication->Invoke(kSharedApplication, + kCallGetArgsPtr); +} \ No newline at end of file diff --git a/Public/Developer/SystemLib/Sources/ApplicationStart.c b/Public/Developer/SystemLib/Sources/ApplicationStart.c new file mode 100644 index 00000000..5b91ba18 --- /dev/null +++ b/Public/Developer/SystemLib/Sources/ApplicationStart.c @@ -0,0 +1,14 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include + +/// @brief Inits the system library. +/// @return if it was succesful or not. +CA_EXTERN_C VoidType __start(VoidType) { + kSharedApplication = RtGetAppObject(); + CA_MUST_PASS(kSharedApplication); +} diff --git a/Public/Developer/SystemLib/Sources/Heap.c b/Public/Developer/SystemLib/Sources/Heap.c new file mode 100644 index 00000000..c9b2b938 --- /dev/null +++ b/Public/Developer/SystemLib/Sources/Heap.c @@ -0,0 +1,42 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include + +/// @brief Allocate from the user's heap. +/// @param sz size of object. +/// @param flags flags. +/// @return +CA_EXTERN_C PtrVoidType RtAllocateProcessPtr(QWordType sz, + DWordType flags) { + CA_MUST_PASS(sz); + CA_MUST_PASS(flags); + + return (PtrVoidType)kSharedApplication->Invoke(kSharedApplication, kCallAllocPtr, sz, flags); +} + +/// @brief Free pointer from the user's heap. +/// @param ptr the pointer to free. +CA_EXTERN_C VoidType RtFreeProcessPtr(PtrVoidType ptr) { + CA_MUST_PASS(ptr); + CA_UNREFERENCED_PARAMETER(kSharedApplication->Invoke(kSharedApplication, kCallFreePtr, ptr)); +} + +/// @brief Get pointer size. +/// @param ptr the pointer to find. +/// @return the size. +CA_EXTERN_C QWordType RtProcessPtrSize(PtrVoidType ptr) { + CA_MUST_PASS(ptr); + return kSharedApplication->Invoke(kSharedApplication, kCallSizePtr, ptr); +} + +/// @brief Check if the pointer exists. +/// @param ptr the pointer to check. +/// @return if it exists +CA_EXTERN_C BooleanType RtProcessPtrExists(PtrVoidType ptr) { + CA_MUST_PASS(ptr); + return kSharedApplication->Invoke(kSharedApplication, kCallCheckPtr, ptr); +} diff --git a/Public/Developer/SystemLib/Sources/Window.c b/Public/Developer/SystemLib/Sources/Window.c new file mode 100644 index 00000000..2527e041 --- /dev/null +++ b/Public/Developer/SystemLib/Sources/Window.c @@ -0,0 +1,70 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include + +/// invalid resource handle, they always start from 1. +#define kInvalidRsrc (0U) + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C WindowPort* WmCreateWindow(const CharacterTypeUTF8* name, + const DWordType rsrcId) { + CA_MUST_PASS(name); + CA_MUST_PASS(rsrcId != kInvalidRsrc); + + return (WindowPort*)kSharedApplication->Invoke( + kSharedApplication, kCallCreateWindow, name, rsrcId); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C VoidType WmReleaseWindow(WindowPort* winPort) { + CA_MUST_PASS(winPort); + + kSharedApplication->Invoke(kSharedApplication, kCallCloseWindow, winPort); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* name, + const DWordType rsrcId) { + CA_MUST_PASS(name); + CA_MUST_PASS(rsrcId != kInvalidRsrc); + + return (WindowPort*)kSharedApplication->Invoke(kSharedApplication, + kCallCreateMenu, name, rsrcId); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* winPort) { + CA_MUST_PASS(winPort); + + kSharedApplication->Invoke(kSharedApplication, kCallCloseMenu, winPort); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C Int32Type WmMoveWindow(WindowPort* id, WmPoint where) { + if (!id) { + return kWmErrInvalidArg; + } + + id->windowPosition.X = where.X; + id->windowPosition.Y = where.Y; + id->windowMoving = True; + + return 0; +} + +/// @brief Color refs. + +const ColorRef kRgbRed = 0x000000FF; +const ColorRef kRgbGreen = 0x0000FF00; +const ColorRef kRgbBlue = 0x00FF0000; +const ColorRef kRgbBlack = 0x00000000; +const ColorRef kRgbWhite = 0xFFFFFFFF; diff --git a/Public/Developer/SystemLib/compile_flags.txt b/Public/Developer/SystemLib/compile_flags.txt new file mode 100644 index 00000000..6e721e73 --- /dev/null +++ b/Public/Developer/SystemLib/compile_flags.txt @@ -0,0 +1,4 @@ +-I./ +-I../ +-I../../../Private +-std=c++20 -- cgit v1.2.3