diff options
| author | Amlal EL Mahrouss <amlal@softwarelabs.com> | 2024-06-09 19:59:14 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlal@softwarelabs.com> | 2024-06-09 19:59:14 +0200 |
| commit | 3cded2a8deaaa8e6907ed1b47d174eb267aab7aa (patch) | |
| tree | c62fd9f4a8ffe55a9c4066f76bed841872155d1b /Usr/Sys/CoreSystem | |
| parent | 9679f4d8676cb72feb80d95bca6ce26965f40042 (diff) | |
MHR-23: Refactor and finishing SMP support.
Diffstat (limited to 'Usr/Sys/CoreSystem')
25 files changed, 828 insertions, 0 deletions
diff --git a/Usr/Sys/CoreSystem/.gitkeep b/Usr/Sys/CoreSystem/.gitkeep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/Usr/Sys/CoreSystem/.gitkeep 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 --- /dev/null +++ b/Usr/Sys/CoreSystem/ARM64/.gitkeep 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 <Headers/Defines.h> + +/// @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 <Headers/Alert.h> + +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 <Headers/Hint.h> + +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<ApplicationInterfaceRef> + +template <SizeType N> +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 <Headers/Defines.h> + +#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 <Headers/Defines.h> + +#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 <Headers/Defines.h> + +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 <Headers/Defines.h> + +/////////////////////////////////////////////////////////////////////// +/// 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 <Headers/Defines.h> + +/// @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 <Headers/Defines.h> + +#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 <Headers/Defines.h> + +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 @@ +<SourceDeploy> + <File name="Headers/Hint.h" hidden="true"/> + <Directory name="Sources/" hidden="true"/> +</SourceDeploy>
\ 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 --- /dev/null +++ b/Usr/Sys/CoreSystem/RISCV/.gitkeep 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 <Headers/Defines.h> + +/// @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 <Headers/Defines.h> + +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 <Headers/Defines.h> +#include <Headers/File.h> + +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 <Headers/Defines.h> +#include <Headers/Heap.h> + +/// @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 <Headers/Math.h> + +/// @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 <Headers/Thread.h> + +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 |
