From 3cded2a8deaaa8e6907ed1b47d174eb267aab7aa Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sun, 9 Jun 2024 19:59:14 +0200 Subject: MHR-23: Refactor and finishing SMP support. --- .vscode/c_cpp_properties.json | 10 +- Doxyfile | 2 +- Kernel/Docs/SPECIFICATION.md | 2 +- SDK/.gitkeep | 0 SDK/Dist/.gitkeep | 0 SDK/Libraries/.gitkeep | 0 SDK/Libraries/CoreCxxRuntime/.gitkeep | 0 SDK/Libraries/CoreCxxRuntime/Private.xml | 3 - .../CoreCxxRuntime/Sources/New+Delete.cxx | 33 --- SDK/Libraries/CorePEFRuntime/.gitkeep | 0 SDK/Libraries/CorePEFRuntime/Private.xml | 3 - SDK/Libraries/CorePEFRuntime/Sources/PEFStart.c | 23 -- SDK/Libraries/CoreSystem/.gitkeep | 0 SDK/Libraries/CoreSystem/AMD64/CoreAssembly.s | 28 --- SDK/Libraries/CoreSystem/ARM64/.gitkeep | 0 SDK/Libraries/CoreSystem/Headers/Alert.h | 25 --- SDK/Libraries/CoreSystem/Headers/Defines.h | 235 -------------------- SDK/Libraries/CoreSystem/Headers/File.h | 57 ----- SDK/Libraries/CoreSystem/Headers/Heap.h | 39 ---- SDK/Libraries/CoreSystem/Headers/Hint.h | 20 -- SDK/Libraries/CoreSystem/Headers/Intl.h | 29 --- SDK/Libraries/CoreSystem/Headers/Math.h | 27 --- SDK/Libraries/CoreSystem/Headers/Rsrc.h | 12 - SDK/Libraries/CoreSystem/Headers/Thread.h | 47 ---- SDK/Libraries/CoreSystem/Headers/Transport.h | 48 ---- SDK/Libraries/CoreSystem/POWER/CoreAssembly.s | 23 -- SDK/Libraries/CoreSystem/Private.xml | 4 - SDK/Libraries/CoreSystem/RISCV/.gitkeep | 0 SDK/Libraries/CoreSystem/ReadMe.md | 13 -- SDK/Libraries/CoreSystem/Sources/App.c | 31 --- SDK/Libraries/CoreSystem/Sources/CRTStartup.c | 12 - SDK/Libraries/CoreSystem/Sources/File.c | 69 ------ SDK/Libraries/CoreSystem/Sources/Heap.c | 54 ----- SDK/Libraries/CoreSystem/Sources/Math.c | 14 -- SDK/Libraries/CoreSystem/Sources/Thread.c | 9 - SDK/Libraries/CoreSystem/amd64.mk | 22 -- SDK/Libraries/CoreSystem/compile_flags.txt | 4 - Usr/.gitkeep | 0 Usr/Dist/.gitkeep | 0 Usr/Sys/.gitkeep | 0 Usr/Sys/CoreCxxRuntime/.gitkeep | 0 Usr/Sys/CoreCxxRuntime/Private.xml | 3 + Usr/Sys/CoreCxxRuntime/Sources/New+Delete.cxx | 33 +++ Usr/Sys/CorePEFRuntime/.gitkeep | 0 Usr/Sys/CorePEFRuntime/Private.xml | 3 + Usr/Sys/CorePEFRuntime/Sources/PEFStart.c | 23 ++ Usr/Sys/CoreSystem/.gitkeep | 0 Usr/Sys/CoreSystem/AMD64/CoreAssembly.s | 28 +++ Usr/Sys/CoreSystem/ARM64/.gitkeep | 0 Usr/Sys/CoreSystem/Headers/Alert.h | 25 +++ Usr/Sys/CoreSystem/Headers/Defines.h | 241 +++++++++++++++++++++ Usr/Sys/CoreSystem/Headers/File.h | 57 +++++ Usr/Sys/CoreSystem/Headers/Heap.h | 39 ++++ Usr/Sys/CoreSystem/Headers/Hint.h | 20 ++ Usr/Sys/CoreSystem/Headers/Intl.h | 29 +++ Usr/Sys/CoreSystem/Headers/Math.h | 27 +++ Usr/Sys/CoreSystem/Headers/Rsrc.h | 12 + Usr/Sys/CoreSystem/Headers/Thread.h | 47 ++++ Usr/Sys/CoreSystem/Headers/Transport.h | 48 ++++ Usr/Sys/CoreSystem/POWER/CoreAssembly.s | 23 ++ Usr/Sys/CoreSystem/Private.xml | 4 + Usr/Sys/CoreSystem/RISCV/.gitkeep | 0 Usr/Sys/CoreSystem/ReadMe.md | 13 ++ Usr/Sys/CoreSystem/Sources/App.c | 31 +++ Usr/Sys/CoreSystem/Sources/CRTStartup.c | 12 + Usr/Sys/CoreSystem/Sources/File.c | 69 ++++++ Usr/Sys/CoreSystem/Sources/Heap.c | 54 +++++ Usr/Sys/CoreSystem/Sources/Math.c | 14 ++ Usr/Sys/CoreSystem/Sources/Thread.c | 9 + Usr/Sys/CoreSystem/amd64.mk | 22 ++ Usr/Sys/CoreSystem/compile_flags.txt | 4 + 71 files changed, 897 insertions(+), 891 deletions(-) delete mode 100644 SDK/.gitkeep delete mode 100644 SDK/Dist/.gitkeep delete mode 100644 SDK/Libraries/.gitkeep delete mode 100644 SDK/Libraries/CoreCxxRuntime/.gitkeep delete mode 100644 SDK/Libraries/CoreCxxRuntime/Private.xml delete mode 100644 SDK/Libraries/CoreCxxRuntime/Sources/New+Delete.cxx delete mode 100644 SDK/Libraries/CorePEFRuntime/.gitkeep delete mode 100644 SDK/Libraries/CorePEFRuntime/Private.xml delete mode 100644 SDK/Libraries/CorePEFRuntime/Sources/PEFStart.c delete mode 100644 SDK/Libraries/CoreSystem/.gitkeep delete mode 100644 SDK/Libraries/CoreSystem/AMD64/CoreAssembly.s delete mode 100644 SDK/Libraries/CoreSystem/ARM64/.gitkeep delete mode 100644 SDK/Libraries/CoreSystem/Headers/Alert.h delete mode 100644 SDK/Libraries/CoreSystem/Headers/Defines.h delete mode 100644 SDK/Libraries/CoreSystem/Headers/File.h delete mode 100644 SDK/Libraries/CoreSystem/Headers/Heap.h delete mode 100644 SDK/Libraries/CoreSystem/Headers/Hint.h delete mode 100644 SDK/Libraries/CoreSystem/Headers/Intl.h delete mode 100644 SDK/Libraries/CoreSystem/Headers/Math.h delete mode 100644 SDK/Libraries/CoreSystem/Headers/Rsrc.h delete mode 100644 SDK/Libraries/CoreSystem/Headers/Thread.h delete mode 100644 SDK/Libraries/CoreSystem/Headers/Transport.h delete mode 100644 SDK/Libraries/CoreSystem/POWER/CoreAssembly.s delete mode 100644 SDK/Libraries/CoreSystem/Private.xml delete mode 100644 SDK/Libraries/CoreSystem/RISCV/.gitkeep delete mode 100644 SDK/Libraries/CoreSystem/ReadMe.md delete mode 100644 SDK/Libraries/CoreSystem/Sources/App.c delete mode 100644 SDK/Libraries/CoreSystem/Sources/CRTStartup.c delete mode 100644 SDK/Libraries/CoreSystem/Sources/File.c delete mode 100644 SDK/Libraries/CoreSystem/Sources/Heap.c delete mode 100644 SDK/Libraries/CoreSystem/Sources/Math.c delete mode 100644 SDK/Libraries/CoreSystem/Sources/Thread.c delete mode 100644 SDK/Libraries/CoreSystem/amd64.mk delete mode 100644 SDK/Libraries/CoreSystem/compile_flags.txt create mode 100644 Usr/.gitkeep create mode 100644 Usr/Dist/.gitkeep create mode 100644 Usr/Sys/.gitkeep create mode 100644 Usr/Sys/CoreCxxRuntime/.gitkeep create mode 100644 Usr/Sys/CoreCxxRuntime/Private.xml create mode 100644 Usr/Sys/CoreCxxRuntime/Sources/New+Delete.cxx create mode 100644 Usr/Sys/CorePEFRuntime/.gitkeep create mode 100644 Usr/Sys/CorePEFRuntime/Private.xml create mode 100644 Usr/Sys/CorePEFRuntime/Sources/PEFStart.c create mode 100644 Usr/Sys/CoreSystem/.gitkeep create mode 100644 Usr/Sys/CoreSystem/AMD64/CoreAssembly.s create mode 100644 Usr/Sys/CoreSystem/ARM64/.gitkeep create mode 100644 Usr/Sys/CoreSystem/Headers/Alert.h create mode 100644 Usr/Sys/CoreSystem/Headers/Defines.h create mode 100644 Usr/Sys/CoreSystem/Headers/File.h create mode 100644 Usr/Sys/CoreSystem/Headers/Heap.h create mode 100644 Usr/Sys/CoreSystem/Headers/Hint.h create mode 100644 Usr/Sys/CoreSystem/Headers/Intl.h create mode 100644 Usr/Sys/CoreSystem/Headers/Math.h create mode 100644 Usr/Sys/CoreSystem/Headers/Rsrc.h create mode 100644 Usr/Sys/CoreSystem/Headers/Thread.h create mode 100644 Usr/Sys/CoreSystem/Headers/Transport.h create mode 100644 Usr/Sys/CoreSystem/POWER/CoreAssembly.s create mode 100644 Usr/Sys/CoreSystem/Private.xml create mode 100644 Usr/Sys/CoreSystem/RISCV/.gitkeep create mode 100644 Usr/Sys/CoreSystem/ReadMe.md create mode 100644 Usr/Sys/CoreSystem/Sources/App.c create mode 100644 Usr/Sys/CoreSystem/Sources/CRTStartup.c create mode 100644 Usr/Sys/CoreSystem/Sources/File.c create mode 100644 Usr/Sys/CoreSystem/Sources/Heap.c create mode 100644 Usr/Sys/CoreSystem/Sources/Math.c create mode 100644 Usr/Sys/CoreSystem/Sources/Thread.c create mode 100644 Usr/Sys/CoreSystem/amd64.mk create mode 100644 Usr/Sys/CoreSystem/compile_flags.txt diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index ff4a5912..c24b99d4 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -7,8 +7,8 @@ "${workspaceFolder}/Drv/**", "${workspaceFolder}/Boot/**", "${workspaceFolder}/**", - "${workspaceFolder}/SDK/Libraries/CoreSystem/**", - "${workspaceFolder}/SDK/Libraries/**" + "${workspaceFolder}/Usr/Sys/CoreSystem/**", + "${workspaceFolder}/Usr/Sys/**" ], "defines": [ "__MAHROUSS__", @@ -28,7 +28,7 @@ { "name": "AppDev ", "includePath": [ - "${workspaceFolder}/SDK/Developer/**" + "${workspaceFolder}/Usr/Developer/**" ], "defines": [], "cStandard": "c17", @@ -42,8 +42,8 @@ "${workspaceFolder}/Kernel/**", "${workspaceFolder}/Boot/**", "${workspaceFolder}/**", - "${workspaceFolder}/SDK/Libraries/CoreSystem/**", - "${workspaceFolder}/SDK/Libraries/**" + "${workspaceFolder}/Usr/Sys/CoreSystem/**", + "${workspaceFolder}/Usr/Sys/**" ], "defines": [ "__MAHROUSS__", diff --git a/Doxyfile b/Doxyfile index aec8485f..120fe24e 100644 --- a/Doxyfile +++ b/Doxyfile @@ -945,7 +945,7 @@ WARN_LOGFILE = INPUT = ./ \ ./NewKernel/ \ - ./SDK/ \ + ./Usr/ \ # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/Kernel/Docs/SPECIFICATION.md b/Kernel/Docs/SPECIFICATION.md index 6f9ac3d3..e58d63ee 100644 --- a/Kernel/Docs/SPECIFICATION.md +++ b/Kernel/Docs/SPECIFICATION.md @@ -24,7 +24,7 @@ - Thread Local Storage. - Semaphore, Locks, Timers. - Canary mechanisms. -- Dynamic Libraries. +- Dynamic Sys. - Cross Platform. - Permission Selectors. diff --git a/SDK/.gitkeep b/SDK/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Dist/.gitkeep b/SDK/Dist/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Libraries/.gitkeep b/SDK/Libraries/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Libraries/CoreCxxRuntime/.gitkeep b/SDK/Libraries/CoreCxxRuntime/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Libraries/CoreCxxRuntime/Private.xml b/SDK/Libraries/CoreCxxRuntime/Private.xml deleted file mode 100644 index 7ee426c0..00000000 --- a/SDK/Libraries/CoreCxxRuntime/Private.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/SDK/Libraries/CoreCxxRuntime/Sources/New+Delete.cxx b/SDK/Libraries/CoreCxxRuntime/Sources/New+Delete.cxx deleted file mode 100644 index cc59586f..00000000 --- a/SDK/Libraries/CoreCxxRuntime/Sources/New+Delete.cxx +++ /dev/null @@ -1,33 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -typedef SizeType size_t; - -void* operator new[](size_t sz) -{ - if (sz == 0) - ++sz; - - return RtHeapAllocate(sz, kStandardAllocation); -} - -void* operator new(size_t sz) -{ - if (sz == 0) - ++sz; - - return RtHeapAllocate(sz, kArrayAllocation); -} - -void operator delete[](void* ptr) -{ - if (ptr == nullptr) - return; - - RtHeapFree(ptr); -} \ No newline at end of file diff --git a/SDK/Libraries/CorePEFRuntime/.gitkeep b/SDK/Libraries/CorePEFRuntime/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Libraries/CorePEFRuntime/Private.xml b/SDK/Libraries/CorePEFRuntime/Private.xml deleted file mode 100644 index 7ee426c0..00000000 --- a/SDK/Libraries/CorePEFRuntime/Private.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/SDK/Libraries/CorePEFRuntime/Sources/PEFStart.c b/SDK/Libraries/CorePEFRuntime/Sources/PEFStart.c deleted file mode 100644 index e9a45f09..00000000 --- a/SDK/Libraries/CorePEFRuntime/Sources/PEFStart.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -/// @brief Application entrypoint. -/// @param void -/// @return void -CS_EXTERN_C VoidType AppMain(VoidType); - -/// @brief Process entrypoint. -/// @param void -/// @return void -CS_EXTERN_C VoidType __ImageStart(VoidType) -{ - kSharedApplication = RtGetAppPointer(); - CS_MUST_PASS(kSharedApplication); - - AppMain(); -} diff --git a/SDK/Libraries/CoreSystem/.gitkeep b/SDK/Libraries/CoreSystem/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Libraries/CoreSystem/AMD64/CoreAssembly.s b/SDK/Libraries/CoreSystem/AMD64/CoreAssembly.s deleted file mode 100644 index 5d1484cf..00000000 --- a/SDK/Libraries/CoreSystem/AMD64/CoreAssembly.s +++ /dev/null @@ -1,28 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - - Purpose: AMD64 low level I/O - -------------------------------------------- */ - -.text - -.globl RtGetAppPointer -.globl RtAssertTriggerInterrupt - -/* @brief Application getter */ -/* @throws: ApptError: appartement error. */ -RtGetAppPointer: - mov $0x10, %rcx /* sysGetProcessObject */ - int $0x32 - - /* rax gets saved and returned. */ - ret - -RtAssertTriggerInterrupt: - mov $0x11, %rcx /* sysTerminateCurrentProcess */ - int $0x32 - - ret - diff --git a/SDK/Libraries/CoreSystem/ARM64/.gitkeep b/SDK/Libraries/CoreSystem/ARM64/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Libraries/CoreSystem/Headers/Alert.h b/SDK/Libraries/CoreSystem/Headers/Alert.h deleted file mode 100644 index 7decd4ca..00000000 --- a/SDK/Libraries/CoreSystem/Headers/Alert.h +++ /dev/null @@ -1,25 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -/************************************************************* - * - * File: Alert.h - * Purpose: New OS alert dialog. - * Date: 3/26/24 - * - * Copyright SoftwareLabs, all rights reserved. - * - *************************************************************/ - -#pragma once - -#include - -/// @brief Shows an alert box, as provided by the OS. -/// @param fmt The alert formating. -/// @param -/// @return -CS_EXTERN_C VoidType UiAlert(const CharacterTypeUTF8* fmt, ...); diff --git a/SDK/Libraries/CoreSystem/Headers/Defines.h b/SDK/Libraries/CoreSystem/Headers/Defines.h deleted file mode 100644 index 713d6df8..00000000 --- a/SDK/Libraries/CoreSystem/Headers/Defines.h +++ /dev/null @@ -1,235 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -#ifdef CS_MUST_PASS -#undef CS_MUST_PASS -#endif - -#ifdef _DEBUG -#define CS_MUST_PASS(e) \ - { \ - if (!e) \ - { \ - UiAlert("Assertion failed.\nExpression :%s\nFile: %s\nLine: %i", #e, __FILE__, __LINE__) RtAssertTriggerInterrupt() \ - } \ - } -#else -#define CS_MUST_PASS(e) CS_UNREFERENCED_PARAMETER(e) -#endif - -#ifdef __cplusplus - -#define CS_EXTERN_C extern "C" - -#else - -#define CS_EXTERN_C extern - -#endif - -#include - -struct ApplicationInterface; -struct GUID; - -CS_EXTERN_C void RtAssertTriggerInterrupt(void); - -#define CS_STDCALL __attribute__((stdcall)) -#define CS_CDECL __attribute__((cdecl)) -#define CS_MSCALL __attribute__((ms_abi)) - -#define PACKED __attribute__((packed)) - -#define CS_PASCAL CS_STDCALL - -#include - -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; - -#ifdef __SINGLE_PRECISION__ -typedef float FloatType; -typedef float PositionType; -#else -typedef double FloatType; -typedef double PositionType; -#endif - -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 Yes 1 -#define No 0 - -#define CS_PTR * - -#define CS_UNREFERENCED_PARAMETER(e) ((VoidType)(e)) - -#ifdef __x86_64__ - -#define CS_FAR __far -#define CS_NEAR __near - -#define _M_AMD64 2 -#else - -#define CS_FAR -#define CS_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 CS_STATIC static -#define CS_INLINE inline -#define CS_CONST const - -#ifdef __cplusplus -#define CS_CONSTEXPR constexpr -#else -#define CS_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, - kCallOpenDir, - kCallCloseDir, - kCallOpenDevice, - kCallCloseDevice, - kCallCreateWindow, - kCallCloseWindow, - kCallCreateMenu, - kCallCloseMenu, - kCallRandomNumberGenerator, - kCallGetArgsCount, - kCallGetArgsPtr, - kCallFileExists, - kCallDirectoryExists, - kCallSymlinkExists, - kCallDeviceExists, - kCallDriveExists, - /// @brief Number of process calls. - kCallsCount, -}; - -/** - * @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 ApplicationInterface -{ - VoidType (*Release)(struct ApplicationInterface* Self, DWordType ExitCode); - IntPtrType (*Invoke)(struct ApplicationInterface* Self, DWordType Sel, ...); - VoidType (*Query)(struct ApplicationInterface* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); -} ApplicationInterface, *ApplicationInterfaceRef; - -#ifdef __cplusplus - -#define CS_COPY_DELETE(KLASS) \ - KLASS& operator=(const KLASS&) = delete; \ - KLASS(const KLASS&) = delete; - -#define CS_COPY_DEFAULT(KLASS) \ - KLASS& operator=(const KLASS&) = default; \ - KLASS(const KLASS&) = default; - -#define CS_MOVE_DELETE(KLASS) \ - KLASS& operator=(KLASS&&) = delete; \ - KLASS(KLASS&&) = delete; - -#define CS_MOVE_DEFAULT(KLASS) \ - KLASS& operator=(KLASS&&) = default; \ - KLASS(KLASS&&) = default; - -#define app_cast reinterpret_cast - -template -using StrType = CharacterTypeUTF8[N]; - -#else - -#define app_cast (ApplicationInterfaceRef) - -#endif // ifdef C++ - -/// @brief Get app singleton. -/// @param -/// @return -CS_EXTERN_C ApplicationInterfaceRef RtGetAppPointer(VoidType); - -/// @brief Get argument count -/// @param -/// @return -CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType); - -/// @brief Get argument pointer. -/// @param -/// @return -CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType); - -CS_EXTERN_C ApplicationInterfaceRef 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/SDK/Libraries/CoreSystem/Headers/File.h b/SDK/Libraries/CoreSystem/Headers/File.h deleted file mode 100644 index cfd9ee30..00000000 --- a/SDK/Libraries/CoreSystem/Headers/File.h +++ /dev/null @@ -1,57 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -#include - -#define kMaxForkNameLength (256U) /* long fork names. */ - -struct _Fork; - -/// @brief Filesystem wrapper. - -typedef QWordType FSRef; - -/// @brief Opens a new file. -/// @param path where to find it. -/// @param rest the restrict (rw, rwe, r+, w+, r, w) -/// @return FSRef the file. -CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, const CharacterTypeUTF8* r); - -/// @brief Closes the file and flushes it to the said file. -/// @param refCS the filesystem reference. -/// @return -CS_EXTERN_C VoidType CSCloseFile(FSRef refCS); - -/// @brief A fork information header. -typedef struct _Fork -{ - Int32Type forkFlags; - Int32Type forkKind; - CharacterTypeUTF8 forkName[kMaxForkNameLength]; - SizeType forkSize; - CharacterTypeUTF8 forkData[]; -} ForkType, ForkTypePtr; - -typedef ForkType* FSForkRef; - -/// @brief Gets the fork inside a file. -/// @param refCS the filesystem ref -/// @param forkName the fork's name -/// @return the fork data. -CS_EXTERN_C FSForkRef CSGetFork(FSRef refCS, const CharacterTypeUTF8* forkName); - -/// @brief Check if the filesystem path is valid. -/// @return if not return false, or true. -CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path); - -/// @brief Flush file -/// @param refCS the file reference. -/// @return -CS_EXTERN_C VoidType CSFlushFile(FSRef refCS); - -/// END OF FILE diff --git a/SDK/Libraries/CoreSystem/Headers/Heap.h b/SDK/Libraries/CoreSystem/Headers/Heap.h deleted file mode 100644 index b2ad6e74..00000000 --- a/SDK/Libraries/CoreSystem/Headers/Heap.h +++ /dev/null @@ -1,39 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -#include - -#define cAllocationKindCount (2U) - -enum CsAllocationKind -{ - kStandardAllocation = 0xC, - kArrayAllocation = 0xD, -}; - -/// @brief Allocates a new pointer from process pool. -/// @param sz the size -/// @param flags the allocation flags. -/// @return -CS_EXTERN_C PtrVoidType CSAllocateHeap(QWordType sz, - DWordType flags); - -/// @brief Check if the pointer exists. -/// @param ptr the pointer to free. -/// @return -CS_EXTERN_C BooleanType CSIsHeapValid(PtrVoidType ptr); - -/// @brief Gets the size of the process' pointer. -/// @param ptr the pointer to free. -/// @return -CS_EXTERN_C QWordType CSGetHeapSize(PtrVoidType ptr); - -/// @brief Frees the process pointer. -/// @param ptr the pointer to free. -/// @return -CS_EXTERN_C VoidType CSFreeHeap(PtrVoidType ptr); diff --git a/SDK/Libraries/CoreSystem/Headers/Hint.h b/SDK/Libraries/CoreSystem/Headers/Hint.h deleted file mode 100644 index ee14711d..00000000 --- a/SDK/Libraries/CoreSystem/Headers/Hint.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -#pragma compiler(hint_manifest) - -#define _Input -#define _Output - -#define _Optional - -#define _StrictCheckInput -#define _StrictCheckOutput - -#define _InOut -#define _StrictInOut diff --git a/SDK/Libraries/CoreSystem/Headers/Intl.h b/SDK/Libraries/CoreSystem/Headers/Intl.h deleted file mode 100644 index b868adca..00000000 --- a/SDK/Libraries/CoreSystem/Headers/Intl.h +++ /dev/null @@ -1,29 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -/// @brief Intlization primitives. - -#include - -typedef UInt64Type IntlRef; - -/// @brief Get app locale. -/// @param name locale name. -/// @return -IntlRef IntlGetLocale(const char* name); - -/// @brief Set app locale. -/// @param intl the locale -/// @return -BooleanType IntlSetLocale(const IntlRef intl); - -/// @brief locale helpers. - -/// @brief translate a string from a locale. -const CharacterTypeUTF8* Intl(const CharacterTypeUTF8* input, - const IntlRef locale); diff --git a/SDK/Libraries/CoreSystem/Headers/Math.h b/SDK/Libraries/CoreSystem/Headers/Math.h deleted file mode 100644 index 0079803e..00000000 --- a/SDK/Libraries/CoreSystem/Headers/Math.h +++ /dev/null @@ -1,27 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -#include - -/////////////////////////////////////////////////////////////////////// -/// Random number generators functions /// -/////////////////////////////////////////////////////////////////////// - -/// @brief Number generator helper. -/// @return Random generated number. -CS_EXTERN_C SizeType MathRand(VoidType); - -/////////////////////////////////////////////////////////////////////// -/// Mathematical functions /// -/////////////////////////////////////////////////////////////////////// - -CS_EXTERN_C FloatType Sqrt(FloatType number); - -CS_EXTERN_C FloatType Cosine(FloatType number); -CS_EXTERN_C FloatType Sine(FloatType number); -CS_EXTERN_C FloatType Tangent(FloatType number); \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Headers/Rsrc.h b/SDK/Libraries/CoreSystem/Headers/Rsrc.h deleted file mode 100644 index 7fe52910..00000000 --- a/SDK/Libraries/CoreSystem/Headers/Rsrc.h +++ /dev/null @@ -1,12 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -#include - -/// @file Rsrc.h -/// @brief RXML forks. \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Headers/Thread.h b/SDK/Libraries/CoreSystem/Headers/Thread.h deleted file mode 100644 index 15b40df3..00000000 --- a/SDK/Libraries/CoreSystem/Headers/Thread.h +++ /dev/null @@ -1,47 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -// -// Created by Amlal on 3/18/24 -// - -#ifndef __THREAD__ -#define __THREAD__ - -#include - -#define kThreadErrorExit (-33) - -/// @brief Thread reference. -typedef QWordType ThreadRef; - -/// @brief Main application thread. -CS_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 -CS_EXTERN_C ThreadRef CSThreadCreate(const CharacterTypeUTF8* threadName, ThreadEntrypointKind threadStart); - -/// @brief Dispoes the thread, and exits with code kThreadErrorExit -/// @param ref the thread reference. -/// @return nothing. -CS_EXTERN_C VoidType CSThreadRelease(ThreadRef ref); - -/// @brief Waits for the thread to complete. -/// @param ref the thread reference. -/// @return nothing. -CS_EXTERN_C VoidType CSThreadJoin(ThreadRef ref); - -/// @brief Yields the current thread. -/// @param ref the thead reference. -/// @return -CS_EXTERN_C VoidType CSThreadYield(ThreadRef ref); - -#endif // __THREAD__ diff --git a/SDK/Libraries/CoreSystem/Headers/Transport.h b/SDK/Libraries/CoreSystem/Headers/Transport.h deleted file mode 100644 index 3f6db3f1..00000000 --- a/SDK/Libraries/CoreSystem/Headers/Transport.h +++ /dev/null @@ -1,48 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -// -// Created by Amlal on 5/12/24 -// - -#ifndef __TRANSPORT__ -#define __TRANSPORT__ - -/// @file: Transport.h -/// @brief Open Transport Layer, an alternative to berkeley sockets. - -#include - -typedef QWordType TrStreamType; - -/// @brief Opens a new socket -/// @param afType address family -/// @param sockType type of socket -/// @param sockProto socket protocol. -/// @return The STREAMS socket. -/// @note return is const. -CS_EXTERN_C CS_CONST TrStreamType CSOpenSocket(UInt32Type afType, UInt32Type sockType, UInt32Type sockProto); - -/// @brief Close a STREAMS socket. -/// @param streams The streams socket. -/// @return -CS_EXTERN_C VoidType CSCloseSocket(CS_CONST TrStreamType streams); - -/// @brief Get OpenTransport version. -/// @param void -/// @return -CS_EXTERN_C CS_CONST Int32Type CSGetVersion(VoidType); - -enum -{ - TrSocketProtoTCP, /// TCP socket - TrSocketProtoUDP, /// UDP socket - TrSocketProtoUN, /// IPC socket - TrSocketProtoRaw, /// Raw socket - TrSocketProtoCount, -}; - -#endif // __TRANSPORT__ \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/POWER/CoreAssembly.s b/SDK/Libraries/CoreSystem/POWER/CoreAssembly.s deleted file mode 100644 index e7919f23..00000000 --- a/SDK/Libraries/CoreSystem/POWER/CoreAssembly.s +++ /dev/null @@ -1,23 +0,0 @@ -; /* ------------------------------------------- -; -; Copyright SoftwareLabs -; -; Purpose: POWER low level I/O -; -; ------------------------------------------- */ - -/* @brief Application getter */ -/* @throws: ApptError: appartement error. */ -export .code64 RtGetAppPointer: - mflr r3 - stw 0x10, 0(r3) /* sysGetProcessObject */ - sc - - blr - -export .code64 RtAssertTriggerInterrupt: - mflr r3 - stw 0x11, 0(r3) /* sysTerminateCurrentProcess */ - sc - - blr diff --git a/SDK/Libraries/CoreSystem/Private.xml b/SDK/Libraries/CoreSystem/Private.xml deleted file mode 100644 index 4be6c388..00000000 --- a/SDK/Libraries/CoreSystem/Private.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/RISCV/.gitkeep b/SDK/Libraries/CoreSystem/RISCV/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Libraries/CoreSystem/ReadMe.md b/SDK/Libraries/CoreSystem/ReadMe.md deleted file mode 100644 index ae5df339..00000000 --- a/SDK/Libraries/CoreSystem/ReadMe.md +++ /dev/null @@ -1,13 +0,0 @@ -# CoreSystem -## Core System framework. - -Currently contains: - -- Heap API. -- File API. -- Data API. -- Threading API. - -Needs to have: -- Device API -- Drive API. \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Sources/App.c b/SDK/Libraries/CoreSystem/Sources/App.c deleted file mode 100644 index 42ea19c6..00000000 --- a/SDK/Libraries/CoreSystem/Sources/App.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -/// @brief Main Application object, retrieved from the RtGetAppPointer symbol. -ApplicationInterfaceRef kSharedApplication = NullPtr; - -/// @brief Gets the app arguments count. -/// @param void no arguments. -/// @return The number of arguments given to the application. -CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) -{ - CS_MUST_PASS(kSharedApplication); - - return kSharedApplication->Invoke(kSharedApplication, kCallGetArgsCount); -} - -/// @brief Gets the app arguments pointer. -/// @param void no arguments. -/// @return -CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType) -{ - CS_MUST_PASS(kSharedApplication); - - return (CharacterTypeUTF8**)kSharedApplication->Invoke(kSharedApplication, - kCallGetArgsPtr); -} diff --git a/SDK/Libraries/CoreSystem/Sources/CRTStartup.c b/SDK/Libraries/CoreSystem/Sources/CRTStartup.c deleted file mode 100644 index 1cfad65d..00000000 --- a/SDK/Libraries/CoreSystem/Sources/CRTStartup.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -VoidType __DllMainCRTStartup(VoidType) -{ - kSharedApplication = RtGetAppPointer(); -} \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Sources/File.c b/SDK/Libraries/CoreSystem/Sources/File.c deleted file mode 100644 index 6e0e810a..00000000 --- a/SDK/Libraries/CoreSystem/Sources/File.c +++ /dev/null @@ -1,69 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include -#include - -enum FileOp -{ - kFlushFile, - kReadFork, - kWriteFork, - kOpenFork, - kCloseFork, -}; - -/// @brief Opens a new file. -/// @param path where to find it. -/// @param rest the restrict (rw, rwe, r+, w+, r, w) -/// @return FSRef the file. -CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, - const CharacterTypeUTF8* rest) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(path && CSIsValidPath(path) == Yes); - CS_MUST_PASS(rest); - - return kSharedApplication->Invoke(kSharedApplication, kCallOpenFile, path, - rest); -} - -/// @brief Closes the file and flushes it to the said file. -/// @param refCS the filesystem reference. -/// @return -CS_EXTERN_C VoidType CSCloseFile(FSRef refCS) -{ - CS_MUST_PASS(kSharedApplication); - - CSFlushFile(refCS); - - kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refCS); -} - -/// @brief Flush file -/// @param refCS the file reference. -/// @return -CS_EXTERN_C VoidType CSFlushFile(FSRef refCS) -{ - CS_MUST_PASS(kSharedApplication); - - kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile); -} - -/// @brief Check if filesystem path is valid. -/// @param path -/// @return -CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(path); - - return kSharedApplication->Invoke(kSharedApplication, kCallFileExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDirectoryExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallSymlinkExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDriveExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDeviceExists, path); -} \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Sources/Heap.c b/SDK/Libraries/CoreSystem/Sources/Heap.c deleted file mode 100644 index e7a77ba5..00000000 --- a/SDK/Libraries/CoreSystem/Sources/Heap.c +++ /dev/null @@ -1,54 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include -#include - -/// @brief Allocate from the user's heap. -/// @param sz size of object. -/// @param flags flags. -/// @return -CS_EXTERN_C PtrVoidType CSAllocateHeap(QWordType sz, DWordType flags) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(sz); - CS_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. -CS_EXTERN_C VoidType CSFreeHeap(PtrVoidType ptr) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(ptr); - - CS_UNREFERENCED_PARAMETER( - kSharedApplication->Invoke(kSharedApplication, kCallFreePtr, ptr)); -} - -/// @brief Get pointer size. -/// @param ptr the pointer to find. -/// @return the size. -CS_EXTERN_C QWordType CSGetHeapSize(PtrVoidType ptr) -{ - CS_MUST_PASS(kSharedApplication); - - CS_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 -CS_EXTERN_C BooleanType CSIsHeapValid(PtrVoidType ptr) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(ptr); - return kSharedApplication->Invoke(kSharedApplication, kCallCheckPtr, ptr); -} diff --git a/SDK/Libraries/CoreSystem/Sources/Math.c b/SDK/Libraries/CoreSystem/Sources/Math.c deleted file mode 100644 index 19df42f3..00000000 --- a/SDK/Libraries/CoreSystem/Sources/Math.c +++ /dev/null @@ -1,14 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -/// @brief Number generator helper. -/// @return Random generated number. -CS_EXTERN_C SizeType MathRand(VoidType) -{ - return kSharedApplication->Invoke(kSharedApplication, kCallRandomNumberGenerator); -} \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Sources/Thread.c b/SDK/Libraries/CoreSystem/Sources/Thread.c deleted file mode 100644 index 7d00bf9e..00000000 --- a/SDK/Libraries/CoreSystem/Sources/Thread.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -ThreadRef kMainThread = 0; diff --git a/SDK/Libraries/CoreSystem/amd64.mk b/SDK/Libraries/CoreSystem/amd64.mk deleted file mode 100644 index e64de90f..00000000 --- a/SDK/Libraries/CoreSystem/amd64.mk +++ /dev/null @@ -1,22 +0,0 @@ -################################################## -# (C) SoftwareLabs, all rights reserved. -# This is the CoreSystem Makefile. -################################################## - -CC=x86_64-w64-mingw32-gcc -AR=x86_64-w64-mingw32-ar -CCINC=-I./ -CCFLAGS=-D__SINGLE_PRECISION__ -nostdlib -std=c17 -ffreestanding -Xlinker --subsystem=17 -e __DllMainCRTStartup -shared -OUTPUT=CoreSystem.lib - -.PHONY: all -all: build-core-amd64 - @echo "[CoreSystem.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 *.lib) diff --git a/SDK/Libraries/CoreSystem/compile_flags.txt b/SDK/Libraries/CoreSystem/compile_flags.txt deleted file mode 100644 index 749a500e..00000000 --- a/SDK/Libraries/CoreSystem/compile_flags.txt +++ /dev/null @@ -1,4 +0,0 @@ --I./ --I../ --I../../../Kernel --std=c17 diff --git a/Usr/.gitkeep b/Usr/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Usr/Dist/.gitkeep b/Usr/Dist/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Usr/Sys/.gitkeep b/Usr/Sys/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Usr/Sys/CoreCxxRuntime/.gitkeep b/Usr/Sys/CoreCxxRuntime/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Usr/Sys/CoreCxxRuntime/Private.xml b/Usr/Sys/CoreCxxRuntime/Private.xml new file mode 100644 index 00000000..7ee426c0 --- /dev/null +++ b/Usr/Sys/CoreCxxRuntime/Private.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Usr/Sys/CoreCxxRuntime/Sources/New+Delete.cxx b/Usr/Sys/CoreCxxRuntime/Sources/New+Delete.cxx new file mode 100644 index 00000000..cc59586f --- /dev/null +++ b/Usr/Sys/CoreCxxRuntime/Sources/New+Delete.cxx @@ -0,0 +1,33 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +typedef SizeType size_t; + +void* operator new[](size_t sz) +{ + if (sz == 0) + ++sz; + + return RtHeapAllocate(sz, kStandardAllocation); +} + +void* operator new(size_t sz) +{ + if (sz == 0) + ++sz; + + return RtHeapAllocate(sz, kArrayAllocation); +} + +void operator delete[](void* ptr) +{ + if (ptr == nullptr) + return; + + RtHeapFree(ptr); +} \ No newline at end of file diff --git a/Usr/Sys/CorePEFRuntime/.gitkeep b/Usr/Sys/CorePEFRuntime/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Usr/Sys/CorePEFRuntime/Private.xml b/Usr/Sys/CorePEFRuntime/Private.xml new file mode 100644 index 00000000..7ee426c0 --- /dev/null +++ b/Usr/Sys/CorePEFRuntime/Private.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Usr/Sys/CorePEFRuntime/Sources/PEFStart.c b/Usr/Sys/CorePEFRuntime/Sources/PEFStart.c new file mode 100644 index 00000000..e9a45f09 --- /dev/null +++ b/Usr/Sys/CorePEFRuntime/Sources/PEFStart.c @@ -0,0 +1,23 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +/// @brief Application entrypoint. +/// @param void +/// @return void +CS_EXTERN_C VoidType AppMain(VoidType); + +/// @brief Process entrypoint. +/// @param void +/// @return void +CS_EXTERN_C VoidType __ImageStart(VoidType) +{ + kSharedApplication = RtGetAppPointer(); + CS_MUST_PASS(kSharedApplication); + + AppMain(); +} diff --git a/Usr/Sys/CoreSystem/.gitkeep b/Usr/Sys/CoreSystem/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Usr/Sys/CoreSystem/AMD64/CoreAssembly.s b/Usr/Sys/CoreSystem/AMD64/CoreAssembly.s new file mode 100644 index 00000000..5d1484cf --- /dev/null +++ b/Usr/Sys/CoreSystem/AMD64/CoreAssembly.s @@ -0,0 +1,28 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + + Purpose: AMD64 low level I/O + +------------------------------------------- */ + +.text + +.globl RtGetAppPointer +.globl RtAssertTriggerInterrupt + +/* @brief Application getter */ +/* @throws: ApptError: appartement error. */ +RtGetAppPointer: + mov $0x10, %rcx /* sysGetProcessObject */ + int $0x32 + + /* rax gets saved and returned. */ + ret + +RtAssertTriggerInterrupt: + mov $0x11, %rcx /* sysTerminateCurrentProcess */ + int $0x32 + + ret + diff --git a/Usr/Sys/CoreSystem/ARM64/.gitkeep b/Usr/Sys/CoreSystem/ARM64/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Usr/Sys/CoreSystem/Headers/Alert.h b/Usr/Sys/CoreSystem/Headers/Alert.h new file mode 100644 index 00000000..7decd4ca --- /dev/null +++ b/Usr/Sys/CoreSystem/Headers/Alert.h @@ -0,0 +1,25 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +/************************************************************* + * + * File: Alert.h + * Purpose: New OS alert dialog. + * Date: 3/26/24 + * + * Copyright SoftwareLabs, all rights reserved. + * + *************************************************************/ + +#pragma once + +#include + +/// @brief Shows an alert box, as provided by the OS. +/// @param fmt The alert formating. +/// @param +/// @return +CS_EXTERN_C VoidType UiAlert(const CharacterTypeUTF8* fmt, ...); diff --git a/Usr/Sys/CoreSystem/Headers/Defines.h b/Usr/Sys/CoreSystem/Headers/Defines.h new file mode 100644 index 00000000..1f35da0a --- /dev/null +++ b/Usr/Sys/CoreSystem/Headers/Defines.h @@ -0,0 +1,241 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#ifdef CS_MUST_PASS +#undef CS_MUST_PASS +#endif + +#ifdef _DEBUG +#define CS_MUST_PASS(e) \ + { \ + if (!e) \ + { \ + UiAlert("Assertion failed.\nExpression :%s\nFile: %s\nLine: %i", #e, __FILE__, __LINE__) RtAssertTriggerInterrupt() \ + } \ + } +#else +#define CS_MUST_PASS(e) CS_UNREFERENCED_PARAMETER(e) +#endif + +#ifdef __cplusplus + +#define CS_EXTERN_C extern "C" + +#else + +#define CS_EXTERN_C extern + +#endif + +#include + +struct ApplicationInterface; +struct GUID; + +CS_EXTERN_C void RtAssertTriggerInterrupt(void); + +#define CS_STDCALL __attribute__((stdcall)) +#define CS_CDECL __attribute__((cdecl)) +#define CS_MSCALL __attribute__((ms_abi)) + +#define PACKED __attribute__((packed)) + +#define CS_PASCAL CS_STDCALL + +#include + +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; + +#ifdef __SINGLE_PRECISION__ +typedef float FloatType; +typedef float PositionType; +#else +typedef double FloatType; +typedef double PositionType; +#endif + +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 Yes 1 +#define No 0 + +#define CS_PTR * + +#define CS_UNREFERENCED_PARAMETER(e) ((VoidType)(e)) + +#ifdef __x86_64__ + +#define CS_FAR __far +#define CS_NEAR __near + +#define _M_AMD64 2 +#else + +#define CS_FAR +#define CS_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 CS_STATIC static +#define CS_INLINE inline +#define CS_CONST const + +#ifdef __cplusplus +#define CS_CONSTEXPR constexpr +#else +#define CS_CONSTEXPR +#endif // __cplusplus + +enum +{ + kCallAllocPtr = 1, + kCallFreePtr, + kCallSizePtr, + kCallCheckPtr, + kCallAllocStack, + /// @brief Open a specific handle + /// (can be used as sel to call methods related to it.) + kCallOpenFile, + kCallCloseFile, + kCallOpenDir, + kCallCloseDir, + kCallOpenDevice, + kCallCloseDevice, + kCallCreateWindow, + kCallCloseWindow, + kCallCreateMenu, + kCallCloseMenu, + kCallRandomNumberGenerator, + kCallGetArgsCount, + kCallGetArgsPtr, + kCallFileExists, + kCallDirectoryExists, + kCallSymlinkExists, + kCallDeviceExists, + kCallDriveExists, + /// @brief Number of process calls. + kCallCount, +}; + +/** + * @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 ApplicationInterface +{ + VoidType (*Release)(struct ApplicationInterface* Self, DWordType ExitCode); + IntPtrType (*Invoke)(struct ApplicationInterface* Self, DWordType Sel, ...); + VoidType (*Query)(struct ApplicationInterface* Self, PtrVoidType* Dst, + SizeType SzDst, struct GUID* GuidOf); +} ApplicationInterface, *ApplicationInterfaceRef; + +#ifdef __cplusplus + +#define CS_COPY_DELETE(KLASS) \ + KLASS& operator=(const KLASS&) = delete; \ + KLASS(const KLASS&) = delete; + +#define CS_COPY_DEFAULT(KLASS) \ + KLASS& operator=(const KLASS&) = default; \ + KLASS(const KLASS&) = default; + +#define CS_MOVE_DELETE(KLASS) \ + KLASS& operator=(KLASS&&) = delete; \ + KLASS(KLASS&&) = delete; + +#define CS_MOVE_DEFAULT(KLASS) \ + KLASS& operator=(KLASS&&) = default; \ + KLASS(KLASS&&) = default; + +#define app_cast reinterpret_cast + +template +using StrType = CharacterTypeUTF8[N]; + +#else + +#define app_cast(X) (ApplicationInterfaceRef)(X) + +#endif // ifdef C++ + +/// @brief Get app singleton. +/// @param +/// @return +CS_EXTERN_C ApplicationInterfaceRef RtGetAppPointer(VoidType); + +/// @brief Get argument count +/// @param +/// @return +CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType); + +/// @brief Get argument pointer. +/// @param +/// @return +CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType); + +/// @brief Shared application interface. +CS_EXTERN_C ApplicationInterfaceRef kSharedApplication; + +/// @brief 255 length string type. +typedef CharacterTypeUTF8 StrType255[255]; + +#define True 1 +#define False 0 +#define Bool BooleanType + +#define NullPtr ((PtrVoidType)0) + +#ifndef kInvalidRef +#define kInvalidRef 0 +#endif + +/// @brief Result type. +typedef UInt64Type ResultType; diff --git a/Usr/Sys/CoreSystem/Headers/File.h b/Usr/Sys/CoreSystem/Headers/File.h new file mode 100644 index 00000000..cfd9ee30 --- /dev/null +++ b/Usr/Sys/CoreSystem/Headers/File.h @@ -0,0 +1,57 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include + +#define kMaxForkNameLength (256U) /* long fork names. */ + +struct _Fork; + +/// @brief Filesystem wrapper. + +typedef QWordType FSRef; + +/// @brief Opens a new file. +/// @param path where to find it. +/// @param rest the restrict (rw, rwe, r+, w+, r, w) +/// @return FSRef the file. +CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, const CharacterTypeUTF8* r); + +/// @brief Closes the file and flushes it to the said file. +/// @param refCS the filesystem reference. +/// @return +CS_EXTERN_C VoidType CSCloseFile(FSRef refCS); + +/// @brief A fork information header. +typedef struct _Fork +{ + Int32Type forkFlags; + Int32Type forkKind; + CharacterTypeUTF8 forkName[kMaxForkNameLength]; + SizeType forkSize; + CharacterTypeUTF8 forkData[]; +} ForkType, ForkTypePtr; + +typedef ForkType* FSForkRef; + +/// @brief Gets the fork inside a file. +/// @param refCS the filesystem ref +/// @param forkName the fork's name +/// @return the fork data. +CS_EXTERN_C FSForkRef CSGetFork(FSRef refCS, const CharacterTypeUTF8* forkName); + +/// @brief Check if the filesystem path is valid. +/// @return if not return false, or true. +CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path); + +/// @brief Flush file +/// @param refCS the file reference. +/// @return +CS_EXTERN_C VoidType CSFlushFile(FSRef refCS); + +/// END OF FILE diff --git a/Usr/Sys/CoreSystem/Headers/Heap.h b/Usr/Sys/CoreSystem/Headers/Heap.h new file mode 100644 index 00000000..b2ad6e74 --- /dev/null +++ b/Usr/Sys/CoreSystem/Headers/Heap.h @@ -0,0 +1,39 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include + +#define cAllocationKindCount (2U) + +enum CsAllocationKind +{ + kStandardAllocation = 0xC, + kArrayAllocation = 0xD, +}; + +/// @brief Allocates a new pointer from process pool. +/// @param sz the size +/// @param flags the allocation flags. +/// @return +CS_EXTERN_C PtrVoidType CSAllocateHeap(QWordType sz, + DWordType flags); + +/// @brief Check if the pointer exists. +/// @param ptr the pointer to free. +/// @return +CS_EXTERN_C BooleanType CSIsHeapValid(PtrVoidType ptr); + +/// @brief Gets the size of the process' pointer. +/// @param ptr the pointer to free. +/// @return +CS_EXTERN_C QWordType CSGetHeapSize(PtrVoidType ptr); + +/// @brief Frees the process pointer. +/// @param ptr the pointer to free. +/// @return +CS_EXTERN_C VoidType CSFreeHeap(PtrVoidType ptr); diff --git a/Usr/Sys/CoreSystem/Headers/Hint.h b/Usr/Sys/CoreSystem/Headers/Hint.h new file mode 100644 index 00000000..ee14711d --- /dev/null +++ b/Usr/Sys/CoreSystem/Headers/Hint.h @@ -0,0 +1,20 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#pragma compiler(hint_manifest) + +#define _Input +#define _Output + +#define _Optional + +#define _StrictCheckInput +#define _StrictCheckOutput + +#define _InOut +#define _StrictInOut diff --git a/Usr/Sys/CoreSystem/Headers/Intl.h b/Usr/Sys/CoreSystem/Headers/Intl.h new file mode 100644 index 00000000..b868adca --- /dev/null +++ b/Usr/Sys/CoreSystem/Headers/Intl.h @@ -0,0 +1,29 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +/// @brief Intlization primitives. + +#include + +typedef UInt64Type IntlRef; + +/// @brief Get app locale. +/// @param name locale name. +/// @return +IntlRef IntlGetLocale(const char* name); + +/// @brief Set app locale. +/// @param intl the locale +/// @return +BooleanType IntlSetLocale(const IntlRef intl); + +/// @brief locale helpers. + +/// @brief translate a string from a locale. +const CharacterTypeUTF8* Intl(const CharacterTypeUTF8* input, + const IntlRef locale); diff --git a/Usr/Sys/CoreSystem/Headers/Math.h b/Usr/Sys/CoreSystem/Headers/Math.h new file mode 100644 index 00000000..0079803e --- /dev/null +++ b/Usr/Sys/CoreSystem/Headers/Math.h @@ -0,0 +1,27 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include + +/////////////////////////////////////////////////////////////////////// +/// Random number generators functions /// +/////////////////////////////////////////////////////////////////////// + +/// @brief Number generator helper. +/// @return Random generated number. +CS_EXTERN_C SizeType MathRand(VoidType); + +/////////////////////////////////////////////////////////////////////// +/// Mathematical functions /// +/////////////////////////////////////////////////////////////////////// + +CS_EXTERN_C FloatType Sqrt(FloatType number); + +CS_EXTERN_C FloatType Cosine(FloatType number); +CS_EXTERN_C FloatType Sine(FloatType number); +CS_EXTERN_C FloatType Tangent(FloatType number); \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Headers/Rsrc.h b/Usr/Sys/CoreSystem/Headers/Rsrc.h new file mode 100644 index 00000000..7fe52910 --- /dev/null +++ b/Usr/Sys/CoreSystem/Headers/Rsrc.h @@ -0,0 +1,12 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include + +/// @file Rsrc.h +/// @brief RXML forks. \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Headers/Thread.h b/Usr/Sys/CoreSystem/Headers/Thread.h new file mode 100644 index 00000000..15b40df3 --- /dev/null +++ b/Usr/Sys/CoreSystem/Headers/Thread.h @@ -0,0 +1,47 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +// +// Created by Amlal on 3/18/24 +// + +#ifndef __THREAD__ +#define __THREAD__ + +#include + +#define kThreadErrorExit (-33) + +/// @brief Thread reference. +typedef QWordType ThreadRef; + +/// @brief Main application thread. +CS_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 +CS_EXTERN_C ThreadRef CSThreadCreate(const CharacterTypeUTF8* threadName, ThreadEntrypointKind threadStart); + +/// @brief Dispoes the thread, and exits with code kThreadErrorExit +/// @param ref the thread reference. +/// @return nothing. +CS_EXTERN_C VoidType CSThreadRelease(ThreadRef ref); + +/// @brief Waits for the thread to complete. +/// @param ref the thread reference. +/// @return nothing. +CS_EXTERN_C VoidType CSThreadJoin(ThreadRef ref); + +/// @brief Yields the current thread. +/// @param ref the thead reference. +/// @return +CS_EXTERN_C VoidType CSThreadYield(ThreadRef ref); + +#endif // __THREAD__ diff --git a/Usr/Sys/CoreSystem/Headers/Transport.h b/Usr/Sys/CoreSystem/Headers/Transport.h new file mode 100644 index 00000000..d78656f3 --- /dev/null +++ b/Usr/Sys/CoreSystem/Headers/Transport.h @@ -0,0 +1,48 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +// +// Created by Amlal on 5/12/24 +// + +#ifndef __TRANSPORT__ +#define __TRANSPORT__ + +/// @file: Transport.h +/// @brief Open Transport Layer, an alternative to berkeley sockets. + +#include + +typedef QWordType TptStreamType; + +/// @brief Opens a new socket +/// @param afType address family +/// @param sockType type of socket +/// @param sockProto socket protocol. +/// @return The STREAMS socket. +/// @note return is const. +CS_EXTERN_C CS_CONST TptStreamType CSOpenSocket(UInt32Type afType, UInt32Type sockType, UInt32Type sockProto); + +/// @brief Close a STREAMS socket. +/// @param streams The streams socket. +/// @return +CS_EXTERN_C VoidType CSCloseSocket(CS_CONST TptStreamType streams); + +/// @brief Get OpenTransport version. +/// @param void +/// @return +CS_EXTERN_C CS_CONST Int32Type CSGetVersion(VoidType); + +enum +{ + TrSocketProtoTCP, /// TCP socket + TrSocketProtoUDP, /// UDP socket + TrSocketProtoUN, /// IPC socket + TrSocketProtoRaw, /// Raw socket + TrSocketProtoCount, +}; + +#endif // __TRANSPORT__ \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/POWER/CoreAssembly.s b/Usr/Sys/CoreSystem/POWER/CoreAssembly.s new file mode 100644 index 00000000..e7919f23 --- /dev/null +++ b/Usr/Sys/CoreSystem/POWER/CoreAssembly.s @@ -0,0 +1,23 @@ +; /* ------------------------------------------- +; +; Copyright SoftwareLabs +; +; Purpose: POWER low level I/O +; +; ------------------------------------------- */ + +/* @brief Application getter */ +/* @throws: ApptError: appartement error. */ +export .code64 RtGetAppPointer: + mflr r3 + stw 0x10, 0(r3) /* sysGetProcessObject */ + sc + + blr + +export .code64 RtAssertTriggerInterrupt: + mflr r3 + stw 0x11, 0(r3) /* sysTerminateCurrentProcess */ + sc + + blr diff --git a/Usr/Sys/CoreSystem/Private.xml b/Usr/Sys/CoreSystem/Private.xml new file mode 100644 index 00000000..4be6c388 --- /dev/null +++ b/Usr/Sys/CoreSystem/Private.xml @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/RISCV/.gitkeep b/Usr/Sys/CoreSystem/RISCV/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Usr/Sys/CoreSystem/ReadMe.md b/Usr/Sys/CoreSystem/ReadMe.md new file mode 100644 index 00000000..ae5df339 --- /dev/null +++ b/Usr/Sys/CoreSystem/ReadMe.md @@ -0,0 +1,13 @@ +# CoreSystem +## Core System framework. + +Currently contains: + +- Heap API. +- File API. +- Data API. +- Threading API. + +Needs to have: +- Device API +- Drive API. \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Sources/App.c b/Usr/Sys/CoreSystem/Sources/App.c new file mode 100644 index 00000000..42ea19c6 --- /dev/null +++ b/Usr/Sys/CoreSystem/Sources/App.c @@ -0,0 +1,31 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +/// @brief Main Application object, retrieved from the RtGetAppPointer symbol. +ApplicationInterfaceRef kSharedApplication = NullPtr; + +/// @brief Gets the app arguments count. +/// @param void no arguments. +/// @return The number of arguments given to the application. +CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) +{ + CS_MUST_PASS(kSharedApplication); + + return kSharedApplication->Invoke(kSharedApplication, kCallGetArgsCount); +} + +/// @brief Gets the app arguments pointer. +/// @param void no arguments. +/// @return +CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType) +{ + CS_MUST_PASS(kSharedApplication); + + return (CharacterTypeUTF8**)kSharedApplication->Invoke(kSharedApplication, + kCallGetArgsPtr); +} diff --git a/Usr/Sys/CoreSystem/Sources/CRTStartup.c b/Usr/Sys/CoreSystem/Sources/CRTStartup.c new file mode 100644 index 00000000..1cfad65d --- /dev/null +++ b/Usr/Sys/CoreSystem/Sources/CRTStartup.c @@ -0,0 +1,12 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +VoidType __DllMainCRTStartup(VoidType) +{ + kSharedApplication = RtGetAppPointer(); +} \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Sources/File.c b/Usr/Sys/CoreSystem/Sources/File.c new file mode 100644 index 00000000..6e0e810a --- /dev/null +++ b/Usr/Sys/CoreSystem/Sources/File.c @@ -0,0 +1,69 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include +#include + +enum FileOp +{ + kFlushFile, + kReadFork, + kWriteFork, + kOpenFork, + kCloseFork, +}; + +/// @brief Opens a new file. +/// @param path where to find it. +/// @param rest the restrict (rw, rwe, r+, w+, r, w) +/// @return FSRef the file. +CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, + const CharacterTypeUTF8* rest) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(path && CSIsValidPath(path) == Yes); + CS_MUST_PASS(rest); + + return kSharedApplication->Invoke(kSharedApplication, kCallOpenFile, path, + rest); +} + +/// @brief Closes the file and flushes it to the said file. +/// @param refCS the filesystem reference. +/// @return +CS_EXTERN_C VoidType CSCloseFile(FSRef refCS) +{ + CS_MUST_PASS(kSharedApplication); + + CSFlushFile(refCS); + + kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refCS); +} + +/// @brief Flush file +/// @param refCS the file reference. +/// @return +CS_EXTERN_C VoidType CSFlushFile(FSRef refCS) +{ + CS_MUST_PASS(kSharedApplication); + + kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile); +} + +/// @brief Check if filesystem path is valid. +/// @param path +/// @return +CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(path); + + return kSharedApplication->Invoke(kSharedApplication, kCallFileExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallDirectoryExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallSymlinkExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallDriveExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallDeviceExists, path); +} \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Sources/Heap.c b/Usr/Sys/CoreSystem/Sources/Heap.c new file mode 100644 index 00000000..e7a77ba5 --- /dev/null +++ b/Usr/Sys/CoreSystem/Sources/Heap.c @@ -0,0 +1,54 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include +#include + +/// @brief Allocate from the user's heap. +/// @param sz size of object. +/// @param flags flags. +/// @return +CS_EXTERN_C PtrVoidType CSAllocateHeap(QWordType sz, DWordType flags) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(sz); + CS_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. +CS_EXTERN_C VoidType CSFreeHeap(PtrVoidType ptr) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(ptr); + + CS_UNREFERENCED_PARAMETER( + kSharedApplication->Invoke(kSharedApplication, kCallFreePtr, ptr)); +} + +/// @brief Get pointer size. +/// @param ptr the pointer to find. +/// @return the size. +CS_EXTERN_C QWordType CSGetHeapSize(PtrVoidType ptr) +{ + CS_MUST_PASS(kSharedApplication); + + CS_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 +CS_EXTERN_C BooleanType CSIsHeapValid(PtrVoidType ptr) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(ptr); + return kSharedApplication->Invoke(kSharedApplication, kCallCheckPtr, ptr); +} diff --git a/Usr/Sys/CoreSystem/Sources/Math.c b/Usr/Sys/CoreSystem/Sources/Math.c new file mode 100644 index 00000000..19df42f3 --- /dev/null +++ b/Usr/Sys/CoreSystem/Sources/Math.c @@ -0,0 +1,14 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +/// @brief Number generator helper. +/// @return Random generated number. +CS_EXTERN_C SizeType MathRand(VoidType) +{ + return kSharedApplication->Invoke(kSharedApplication, kCallRandomNumberGenerator); +} \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Sources/Thread.c b/Usr/Sys/CoreSystem/Sources/Thread.c new file mode 100644 index 00000000..7d00bf9e --- /dev/null +++ b/Usr/Sys/CoreSystem/Sources/Thread.c @@ -0,0 +1,9 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +ThreadRef kMainThread = 0; diff --git a/Usr/Sys/CoreSystem/amd64.mk b/Usr/Sys/CoreSystem/amd64.mk new file mode 100644 index 00000000..e64de90f --- /dev/null +++ b/Usr/Sys/CoreSystem/amd64.mk @@ -0,0 +1,22 @@ +################################################## +# (C) SoftwareLabs, all rights reserved. +# This is the CoreSystem Makefile. +################################################## + +CC=x86_64-w64-mingw32-gcc +AR=x86_64-w64-mingw32-ar +CCINC=-I./ +CCFLAGS=-D__SINGLE_PRECISION__ -nostdlib -std=c17 -ffreestanding -Xlinker --subsystem=17 -e __DllMainCRTStartup -shared +OUTPUT=CoreSystem.lib + +.PHONY: all +all: build-core-amd64 + @echo "[CoreSystem.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 *.lib) diff --git a/Usr/Sys/CoreSystem/compile_flags.txt b/Usr/Sys/CoreSystem/compile_flags.txt new file mode 100644 index 00000000..749a500e --- /dev/null +++ b/Usr/Sys/CoreSystem/compile_flags.txt @@ -0,0 +1,4 @@ +-I./ +-I../ +-I../../../Kernel +-std=c17 -- cgit v1.2.3